[pthreads] Use pthread table for pthread management.

This commit is contained in:
Bernard Xiong committed 2019-05-12 17:56:11 +08:00
1 parent b7cc4e9c8a
commit 5d36fa78c0
5 files changed
+207 -102

No files matched your search

File diff suppressed because it is too large. Load diff
+2 -5
View File
@@ -32,7 +32,7 @@ extern "C" {
#define PTHREAD_EXPLICIT_SCHED 0
#define PTHREAD_INHERIT_SCHED 1
typedef rt_thread_t pthread_t;
typedef long pthread_t;
typedef long pthread_condattr_t;
typedef long pthread_rwlockattr_t;
typedef long pthread_mutexattr_t;
@@ -172,10 +172,7 @@ rt_inline int pthread_equal (pthread_t t1, pthread_t t2)
return t1 == t2;
}
rt_inline pthread_t pthread_self (void)
{
return rt_thread_self();
}
pthread_t pthread_self (void);
void pthread_exit (void *value_ptr);
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
+1 -1
View File
@@ -189,7 +189,7 @@ rt_err_t _pthread_cond_timedwait(pthread_cond_t *cond,
pthread_cond_init(cond, RT_NULL);
/* The mutex was not owned by the current thread at the time of the call. */
if (mutex->lock.owner != pthread_self())
if (mutex->lock.owner != rt_thread_self())
return -RT_ERROR;
/* unlock a mutex failed */
if (pthread_mutex_unlock(mutex) != 0)
+2 -11
View File
@@ -30,6 +30,7 @@ struct _pthread_key_data
};
typedef struct _pthread_key_data _pthread_key_data_t;
#define PTHREAD_NUM_MAX 32
#define PTHREAD_MAGIC 0x70746873
struct _pthread_data
{
@@ -56,17 +57,7 @@ struct _pthread_data
};
typedef struct _pthread_data _pthread_data_t;
rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
{
_pthread_data_t *ptd;
RT_ASSERT(thread != RT_NULL);
ptd = (_pthread_data_t *)thread->user_data;
RT_ASSERT(ptd != RT_NULL);
RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
return ptd;
}
_pthread_data_t *_pthread_get_data(pthread_t thread);
int clock_time_to_tick(const struct timespec *time);
+8 -2
View File
@@ -22,7 +22,10 @@ void *pthread_getspecific(pthread_key_t key)
{
struct _pthread_data* ptd;
ptd = _pthread_get_data(rt_thread_self());
if (rt_thread_self() == NULL) return NULL;
/* get pthread data from user data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data;
RT_ASSERT(ptd != NULL);
if (ptd->tls == NULL)
@@ -39,7 +42,10 @@ int pthread_setspecific(pthread_key_t key, const void *value)
{
struct _pthread_data* ptd;
ptd = _pthread_get_data(rt_thread_self());
if (rt_thread_self() == NULL) return EINVAL;
/* get pthread data from user data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data;
RT_ASSERT(ptd != NULL);
/* check tls area */