Make pthread_t a void *

parent dc52dd28
...@@ -101,17 +101,6 @@ pthread_create (pthread_t * tid, ...@@ -101,17 +101,6 @@ pthread_create (pthread_t * tid,
pthread_t self; pthread_t self;
pte_osResult osResult; pte_osResult osResult;
/*
* Before doing anything, check that tid can be stored through
* without invoking a memory protection error (segfault).
* Make sure that the assignment below can't be optimised out by the compiler.
* This is assured by conditionally assigning *tid again at the end.
*/
if (tid != NULL)
{
tid->x = 0;
}
if (attr != NULL) if (attr != NULL)
{ {
a = *attr; a = *attr;
...@@ -121,12 +110,12 @@ pthread_create (pthread_t * tid, ...@@ -121,12 +110,12 @@ pthread_create (pthread_t * tid,
a = NULL; a = NULL;
} }
if ((thread = pte_new ()).p == NULL) if ((thread = pte_new ()) == NULL)
{ {
goto FAIL0; goto FAIL0;
} }
tp = (pte_thread_t *) thread.p; tp = (pte_thread_t *) thread;
priority = tp->sched_priority; priority = tp->sched_priority;
...@@ -167,7 +156,7 @@ pthread_create (pthread_t * tid, ...@@ -167,7 +156,7 @@ pthread_create (pthread_t * tid,
* system adjustment. This is not the case for POSIX threads. * system adjustment. This is not the case for POSIX threads.
*/ */
self = pthread_self (); self = pthread_self ();
priority = ((pte_thread_t *) self.p)->sched_priority; priority = ((pte_thread_t *) self)->sched_priority;
} }
......
...@@ -75,11 +75,11 @@ pte_callUserDestroyRoutines (pthread_t thread) ...@@ -75,11 +75,11 @@ pte_callUserDestroyRoutines (pthread_t thread)
{ {
ThreadKeyAssoc * assoc; ThreadKeyAssoc * assoc;
if (thread.p != NULL) if (thread != NULL)
{ {
int assocsRemaining; int assocsRemaining;
int iterations = 0; int iterations = 0;
pte_thread_t * sp = (pte_thread_t *) thread.p; pte_thread_t * sp = (pte_thread_t *) thread;
/* /*
* Run through all Thread<-->Key associations * Run through all Thread<-->Key associations
......
...@@ -56,7 +56,7 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout ...@@ -56,7 +56,7 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout
pte_thread_t * sp; pte_thread_t * sp;
self = pthread_self(); self = pthread_self();
sp = (pte_thread_t *) self.p; sp = (pte_thread_t *) self;
if (sp != NULL) if (sp != NULL)
{ {
...@@ -127,4 +127,3 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout ...@@ -127,4 +127,3 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout
return (result); return (result);
} /* CancelableWait */ } /* CancelableWait */
...@@ -52,7 +52,7 @@ pthread_t ...@@ -52,7 +52,7 @@ pthread_t
pte_new (void) pte_new (void)
{ {
pthread_t t; pthread_t t;
pthread_t nil = {NULL, 0}; pthread_t nil = NULL;
pte_thread_t * tp; pte_thread_t * tp;
/* /*
...@@ -60,9 +60,9 @@ pte_new (void) ...@@ -60,9 +60,9 @@ pte_new (void)
*/ */
t = pte_threadReusePop (); t = pte_threadReusePop ();
if (NULL != t.p) if (NULL != t)
{ {
tp = (pte_thread_t *) t.p; tp = (pte_thread_t *) t;
} }
else else
{ {
...@@ -75,8 +75,7 @@ pte_new (void) ...@@ -75,8 +75,7 @@ pte_new (void)
} }
/* ptHandle.p needs to point to it's parent pte_thread_t. */ /* ptHandle.p needs to point to it's parent pte_thread_t. */
t.p = tp->ptHandle.p = tp; t = tp->ptHandle = tp;
t.x = tp->ptHandle.x = 0;
} }
/* Set default state. */ /* Set default state. */
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
pthread_t pthread_t
pte_threadReusePop (void) pte_threadReusePop (void)
{ {
pthread_t t = {NULL, 0}; pthread_t t = NULL;
pte_osMutexLock (pte_thread_reuse_lock); pte_osMutexLock (pte_thread_reuse_lock);
...@@ -122,7 +122,7 @@ pte_threadReusePop (void) ...@@ -122,7 +122,7 @@ pte_threadReusePop (void)
void void
pte_threadReusePush (pthread_t thread) pte_threadReusePush (pthread_t thread)
{ {
pte_thread_t * tp = (pte_thread_t *) thread.p; pte_thread_t * tp = (pte_thread_t *) thread;
pthread_t t; pthread_t t;
...@@ -134,13 +134,6 @@ pte_threadReusePush (pthread_t thread) ...@@ -134,13 +134,6 @@ pte_threadReusePush (pthread_t thread)
/* Must restore the original POSIX handle that we just wiped. */ /* Must restore the original POSIX handle that we just wiped. */
tp->ptHandle = t; tp->ptHandle = t;
/* Bump the reuse counter now */
#ifdef PTE_THREAD_ID_REUSE_INCREMENT
tp->ptHandle.x += PTE_THREAD_ID_REUSE_INCREMENT;
#else
tp->ptHandle.x++;
#endif
tp->prevReuse = PTE_THREAD_REUSE_EMPTY; tp->prevReuse = PTE_THREAD_REUSE_EMPTY;
if (PTE_THREAD_REUSE_EMPTY != pte_threadReuseBottom) if (PTE_THREAD_REUSE_EMPTY != pte_threadReuseBottom)
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
static void static void
pte_threadDestroyCommon (pthread_t thread, unsigned char shouldThreadExit) pte_threadDestroyCommon (pthread_t thread, unsigned char shouldThreadExit)
{ {
pte_thread_t * tp = (pte_thread_t *) thread.p; pte_thread_t * tp = (pte_thread_t *) thread;
pte_thread_t threadCopy; pte_thread_t threadCopy;
if (tp != NULL) if (tp != NULL)
...@@ -98,4 +98,3 @@ void pte_threadExitAndDestroy (pthread_t thread) ...@@ -98,4 +98,3 @@ void pte_threadExitAndDestroy (pthread_t thread)
{ {
pte_threadDestroyCommon(thread,1); pte_threadDestroyCommon(thread,1);
} }
...@@ -92,7 +92,7 @@ int pte_threadStart (void *vthreadParms) ...@@ -92,7 +92,7 @@ int pte_threadStart (void *vthreadParms)
void * status = (void *) 0; void * status = (void *) 0;
self = threadParms->tid; self = threadParms->tid;
sp = (pte_thread_t *) self.p; sp = (pte_thread_t *) self;
start = threadParms->start; start = threadParms->start;
arg = threadParms->arg; arg = threadParms->arg;
// free (threadParms); // free (threadParms);
...@@ -245,4 +245,3 @@ int pte_threadStart (void *vthreadParms) ...@@ -245,4 +245,3 @@ int pte_threadStart (void *vthreadParms)
return (unsigned) status; return (unsigned) status;
} /* pte_threadStart */ } /* pte_threadStart */
...@@ -386,19 +386,7 @@ enum ...@@ -386,19 +386,7 @@ enum
#undef SEM_VALUE_MAX #undef SEM_VALUE_MAX
#define SEM_VALUE_MAX INT_MAX #define SEM_VALUE_MAX INT_MAX
typedef void * pthread_t;
/*
* Generic handle type - intended to extend uniqueness beyond
* that available with a simple pointer. It should scale for either
* IA-32 or IA-64.
*/
typedef struct
{
void * p; /* Pointer to actual object */
unsigned int x; /* Extra information - reuse count etc */
} pte_handle_t;
typedef pte_handle_t pthread_t;
typedef struct pthread_attr_t_ * pthread_attr_t; typedef struct pthread_attr_t_ * pthread_attr_t;
typedef struct pthread_once_t_ pthread_once_t; typedef struct pthread_once_t_ pthread_once_t;
typedef struct pthread_key_t_ * pthread_key_t; typedef struct pthread_key_t_ * pthread_key_t;
......
...@@ -80,7 +80,7 @@ pthread_cancel (pthread_t thread) ...@@ -80,7 +80,7 @@ pthread_cancel (pthread_t thread)
return result; return result;
} }
if ((self = pthread_self ()).p == NULL) if ((self = pthread_self ()) == NULL)
{ {
return ENOMEM; return ENOMEM;
}; };
...@@ -101,7 +101,7 @@ pthread_cancel (pthread_t thread) ...@@ -101,7 +101,7 @@ pthread_cancel (pthread_t thread)
*/ */
cancel_self = pthread_equal (thread, self); cancel_self = pthread_equal (thread, self);
tp = (pte_thread_t *) thread.p; tp = (pte_thread_t *) thread;
/* /*
* Lock for async-cancel safety. * Lock for async-cancel safety.
......
...@@ -117,12 +117,12 @@ pthread_delay_np (struct timespec *interval) ...@@ -117,12 +117,12 @@ pthread_delay_np (struct timespec *interval)
wait_time = secs_in_millisecs + millisecs; wait_time = secs_in_millisecs + millisecs;
if (NULL == (self = pthread_self ()).p) if (NULL == (self = pthread_self ()))
{ {
return ENOMEM; return ENOMEM;
} }
sp = (pte_thread_t *) self.p; sp = (pte_thread_t *) self;
if (sp->cancelState == PTHREAD_CANCEL_ENABLE) if (sp->cancelState == PTHREAD_CANCEL_ENABLE)
{ {
......
...@@ -75,13 +75,12 @@ pthread_detach (pthread_t thread) ...@@ -75,13 +75,12 @@ pthread_detach (pthread_t thread)
{ {
int result; int result;
unsigned char destroyIt = PTE_FALSE; unsigned char destroyIt = PTE_FALSE;
pte_thread_t * tp = (pte_thread_t *) thread.p; pte_thread_t * tp = (pte_thread_t *) thread;
pte_osMutexLock (pte_thread_reuse_lock); pte_osMutexLock (pte_thread_reuse_lock);
if (NULL == tp if (NULL == tp)
|| thread.x != tp->ptHandle.x)
{ {
result = ESRCH; result = ESRCH;
} }
......
...@@ -75,7 +75,7 @@ pthread_equal (pthread_t t1, pthread_t t2) ...@@ -75,7 +75,7 @@ pthread_equal (pthread_t t1, pthread_t t2)
* We also accept NULL == NULL - treating NULL as a thread * We also accept NULL == NULL - treating NULL as a thread
* for this special case, because there is no error that we can return. * for this special case, because there is no error that we can return.
*/ */
result = ( t1.p == t2.p && t1.x == t2.x ); result = ( t1 == t2 );
return (result); return (result);
......
...@@ -75,7 +75,7 @@ pthread_getschedparam (pthread_t thread, int *policy, ...@@ -75,7 +75,7 @@ pthread_getschedparam (pthread_t thread, int *policy,
* for the target thread. It must not return the actual thread * for the target thread. It must not return the actual thread
* priority as altered by any system priority adjustments etc. * priority as altered by any system priority adjustments etc.
*/ */
param->sched_priority = ((pte_thread_t *)thread.p)->sched_priority; param->sched_priority = ((pte_thread_t *)thread)->sched_priority;
return 0; return 0;
} }
...@@ -85,13 +85,12 @@ pthread_join (pthread_t thread, void **value_ptr) ...@@ -85,13 +85,12 @@ pthread_join (pthread_t thread, void **value_ptr)
{ {
int result; int result;
pthread_t self; pthread_t self;
pte_thread_t * tp = (pte_thread_t *) thread.p; pte_thread_t * tp = (pte_thread_t *) thread;
pte_osMutexLock (pte_thread_reuse_lock); pte_osMutexLock (pte_thread_reuse_lock);
if (NULL == tp if (NULL == tp)
|| thread.x != tp->ptHandle.x)
{ {
result = ESRCH; result = ESRCH;
} }
...@@ -113,7 +112,7 @@ pthread_join (pthread_t thread, void **value_ptr) ...@@ -113,7 +112,7 @@ pthread_join (pthread_t thread, void **value_ptr)
*/ */
self = pthread_self(); self = pthread_self();
if (NULL == self.p) if (NULL == self)
{ {
result = ENOENT; result = ENOENT;
} }
......
...@@ -83,10 +83,9 @@ pthread_kill (pthread_t thread, int sig) ...@@ -83,10 +83,9 @@ pthread_kill (pthread_t thread, int sig)
pte_osMutexLock (pte_thread_reuse_lock); pte_osMutexLock (pte_thread_reuse_lock);
tp = (pte_thread_t *) thread.p; tp = (pte_thread_t *) thread;
if (NULL == tp if (NULL == tp
|| thread.x != tp->ptHandle.x
|| 0 == tp->threadId) || 0 == tp->threadId)
{ {
result = ESRCH; result = ESRCH;
......
...@@ -71,7 +71,7 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) ...@@ -71,7 +71,7 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr)
mx->recursive_count = 0; mx->recursive_count = 0;
mx->kind = (attr == NULL || *attr == NULL mx->kind = (attr == NULL || *attr == NULL
? PTHREAD_MUTEX_DEFAULT : (*attr)->kind); ? PTHREAD_MUTEX_DEFAULT : (*attr)->kind);
mx->ownerThread.p = NULL; mx->ownerThread = NULL;
pte_osSemaphoreCreate(0,&mx->handle); pte_osSemaphoreCreate(0,&mx->handle);
......
...@@ -103,7 +103,7 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) ...@@ -103,7 +103,7 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)
if (mx->kind != PTHREAD_MUTEX_RECURSIVE if (mx->kind != PTHREAD_MUTEX_RECURSIVE
|| 0 == --mx->recursive_count) || 0 == --mx->recursive_count)
{ {
mx->ownerThread.p = NULL; mx->ownerThread = NULL;
if (PTE_ATOMIC_EXCHANGE (&mx->lock_idx,0) < 0) if (PTE_ATOMIC_EXCHANGE (&mx->lock_idx,0) < 0)
{ {
......
...@@ -88,7 +88,7 @@ pthread_self (void) ...@@ -88,7 +88,7 @@ pthread_self (void)
* by pte_new! * by pte_new!
*/ */
self = pte_new (); self = pte_new ();
sp = (pte_thread_t *) self.p; sp = (pte_thread_t *) self;
if (sp != NULL) if (sp != NULL)
{ {
......
...@@ -87,7 +87,7 @@ pthread_setcancelstate (int state, int *oldstate) ...@@ -87,7 +87,7 @@ pthread_setcancelstate (int state, int *oldstate)
{ {
int result = 0; int result = 0;
pthread_t self = pthread_self (); pthread_t self = pthread_self ();
pte_thread_t * sp = (pte_thread_t *) self.p; pte_thread_t * sp = (pte_thread_t *) self;
if (sp == NULL if (sp == NULL
|| (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE)) || (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE))
......
...@@ -88,7 +88,7 @@ pthread_setcanceltype (int type, int *oldtype) ...@@ -88,7 +88,7 @@ pthread_setcanceltype (int type, int *oldtype)
{ {
int result = 0; int result = 0;
pthread_t self = pthread_self (); pthread_t self = pthread_self ();
pte_thread_t * sp = (pte_thread_t *) self.p; pte_thread_t * sp = (pte_thread_t *) self;
#ifndef PTE_SUPPORT_ASYNC_CANCEL #ifndef PTE_SUPPORT_ASYNC_CANCEL
if (type == PTHREAD_CANCEL_ASYNCHRONOUS) if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
......
...@@ -78,7 +78,7 @@ pte_setthreadpriority (pthread_t thread, int policy, int priority) ...@@ -78,7 +78,7 @@ pte_setthreadpriority (pthread_t thread, int policy, int priority)
{ {
int prio; int prio;
int result; int result;
pte_thread_t * tp = (pte_thread_t *) thread.p; pte_thread_t * tp = (pte_thread_t *) thread;
prio = priority; prio = priority;
......
...@@ -84,7 +84,7 @@ pthread_setspecific (pthread_key_t key, const void *value) ...@@ -84,7 +84,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
* thread if one wasn't explicitly created * thread if one wasn't explicitly created
*/ */
self = pthread_self (); self = pthread_self ();
if (self.p == NULL) if (self == NULL)
{ {
return ENOENT; return ENOENT;
} }
...@@ -116,7 +116,7 @@ pthread_setspecific (pthread_key_t key, const void *value) ...@@ -116,7 +116,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
if (key != NULL) if (key != NULL)
{ {
if (self.p != NULL && key->destructor != NULL && value != NULL) if (self != NULL && key->destructor != NULL && value != NULL)
{ {
/* /*
* Only require associations if we have to * Only require associations if we have to
...@@ -131,7 +131,7 @@ pthread_setspecific (pthread_key_t key, const void *value) ...@@ -131,7 +131,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
if (pthread_mutex_lock(&(key->keyLock)) == 0) if (pthread_mutex_lock(&(key->keyLock)) == 0)
{ {
pte_thread_t * sp = (pte_thread_t *) self.p; pte_thread_t * sp = (pte_thread_t *) self;
(void) pthread_mutex_lock(&(sp->threadLock)); (void) pthread_mutex_lock(&(sp->threadLock));
......
...@@ -75,7 +75,7 @@ pthread_testcancel (void) ...@@ -75,7 +75,7 @@ pthread_testcancel (void)
*/ */
{ {
pthread_t self = pthread_self (); pthread_t self = pthread_self ();
pte_thread_t * sp = (pte_thread_t *) self.p; pte_thread_t * sp = (pte_thread_t *) self;
if (sp == NULL) if (sp == NULL)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment