Commit a12978cc authored by Jeremy Soller's avatar Jeremy Soller

Make pthread_t a void *

parent dc52dd28
......@@ -101,17 +101,6 @@ pthread_create (pthread_t * tid,
pthread_t self;
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)
{
a = *attr;
......@@ -121,12 +110,12 @@ pthread_create (pthread_t * tid,
a = NULL;
}
if ((thread = pte_new ()).p == NULL)
if ((thread = pte_new ()) == NULL)
{
goto FAIL0;
}
tp = (pte_thread_t *) thread.p;
tp = (pte_thread_t *) thread;
priority = tp->sched_priority;
......@@ -167,7 +156,7 @@ pthread_create (pthread_t * tid,
* system adjustment. This is not the case for POSIX threads.
*/
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)
{
ThreadKeyAssoc * assoc;
if (thread.p != NULL)
if (thread != NULL)
{
int assocsRemaining;
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
......
......@@ -56,7 +56,7 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout
pte_thread_t * sp;
self = pthread_self();
sp = (pte_thread_t *) self.p;
sp = (pte_thread_t *) self;
if (sp != NULL)
{
......@@ -127,4 +127,3 @@ int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout
return (result);
} /* CancelableWait */
......@@ -52,7 +52,7 @@ pthread_t
pte_new (void)
{
pthread_t t;
pthread_t nil = {NULL, 0};
pthread_t nil = NULL;
pte_thread_t * tp;
/*
......@@ -60,9 +60,9 @@ pte_new (void)
*/
t = pte_threadReusePop ();
if (NULL != t.p)
if (NULL != t)
{
tp = (pte_thread_t *) t.p;
tp = (pte_thread_t *) t;
}
else
{
......@@ -75,8 +75,7 @@ pte_new (void)
}
/* ptHandle.p needs to point to it's parent pte_thread_t. */
t.p = tp->ptHandle.p = tp;
t.x = tp->ptHandle.x = 0;
t = tp->ptHandle = tp;
}
/* Set default state. */
......
......@@ -84,7 +84,7 @@
pthread_t
pte_threadReusePop (void)
{
pthread_t t = {NULL, 0};
pthread_t t = NULL;
pte_osMutexLock (pte_thread_reuse_lock);
......@@ -122,7 +122,7 @@ pte_threadReusePop (void)
void
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;
......@@ -134,13 +134,6 @@ pte_threadReusePush (pthread_t thread)
/* Must restore the original POSIX handle that we just wiped. */
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;
if (PTE_THREAD_REUSE_EMPTY != pte_threadReuseBottom)
......
......@@ -53,7 +53,7 @@
static void
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;
if (tp != NULL)
......@@ -98,4 +98,3 @@ void pte_threadExitAndDestroy (pthread_t thread)
{
pte_threadDestroyCommon(thread,1);
}
......@@ -92,7 +92,7 @@ int pte_threadStart (void *vthreadParms)
void * status = (void *) 0;
self = threadParms->tid;
sp = (pte_thread_t *) self.p;
sp = (pte_thread_t *) self;
start = threadParms->start;
arg = threadParms->arg;
// free (threadParms);
......@@ -245,4 +245,3 @@ int pte_threadStart (void *vthreadParms)
return (unsigned) status;
} /* pte_threadStart */
......@@ -386,19 +386,7 @@ enum
#undef SEM_VALUE_MAX
#define SEM_VALUE_MAX INT_MAX
/*
* 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 void * pthread_t;
typedef struct pthread_attr_t_ * pthread_attr_t;
typedef struct pthread_once_t_ pthread_once_t;
typedef struct pthread_key_t_ * pthread_key_t;
......
......@@ -80,7 +80,7 @@ pthread_cancel (pthread_t thread)
return result;
}
if ((self = pthread_self ()).p == NULL)
if ((self = pthread_self ()) == NULL)
{
return ENOMEM;
};
......@@ -101,7 +101,7 @@ pthread_cancel (pthread_t thread)
*/
cancel_self = pthread_equal (thread, self);
tp = (pte_thread_t *) thread.p;
tp = (pte_thread_t *) thread;
/*
* Lock for async-cancel safety.
......
......@@ -117,12 +117,12 @@ pthread_delay_np (struct timespec *interval)
wait_time = secs_in_millisecs + millisecs;
if (NULL == (self = pthread_self ()).p)
if (NULL == (self = pthread_self ()))
{
return ENOMEM;
}
sp = (pte_thread_t *) self.p;
sp = (pte_thread_t *) self;
if (sp->cancelState == PTHREAD_CANCEL_ENABLE)
{
......
......@@ -75,13 +75,12 @@ pthread_detach (pthread_t thread)
{
int result;
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);
if (NULL == tp
|| thread.x != tp->ptHandle.x)
if (NULL == tp)
{
result = ESRCH;
}
......
......@@ -75,7 +75,7 @@ pthread_equal (pthread_t t1, pthread_t t2)
* We also accept NULL == NULL - treating NULL as a thread
* 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);
......
......@@ -75,7 +75,7 @@ pthread_getschedparam (pthread_t thread, int *policy,
* for the target thread. It must not return the actual thread
* 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;
}
......@@ -85,13 +85,12 @@ pthread_join (pthread_t thread, void **value_ptr)
{
int result;
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);
if (NULL == tp
|| thread.x != tp->ptHandle.x)
if (NULL == tp)
{
result = ESRCH;
}
......@@ -113,7 +112,7 @@ pthread_join (pthread_t thread, void **value_ptr)
*/
self = pthread_self();
if (NULL == self.p)
if (NULL == self)
{
result = ENOENT;
}
......
......@@ -83,10 +83,9 @@ pthread_kill (pthread_t thread, int sig)
pte_osMutexLock (pte_thread_reuse_lock);
tp = (pte_thread_t *) thread.p;
tp = (pte_thread_t *) thread;
if (NULL == tp
|| thread.x != tp->ptHandle.x
|| 0 == tp->threadId)
{
result = ESRCH;
......
......@@ -71,7 +71,7 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr)
mx->recursive_count = 0;
mx->kind = (attr == NULL || *attr == NULL
? PTHREAD_MUTEX_DEFAULT : (*attr)->kind);
mx->ownerThread.p = NULL;
mx->ownerThread = NULL;
pte_osSemaphoreCreate(0,&mx->handle);
......
......@@ -103,7 +103,7 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)
if (mx->kind != PTHREAD_MUTEX_RECURSIVE
|| 0 == --mx->recursive_count)
{
mx->ownerThread.p = NULL;
mx->ownerThread = NULL;
if (PTE_ATOMIC_EXCHANGE (&mx->lock_idx,0) < 0)
{
......
......@@ -88,7 +88,7 @@ pthread_self (void)
* by pte_new!
*/
self = pte_new ();
sp = (pte_thread_t *) self.p;
sp = (pte_thread_t *) self;
if (sp != NULL)
{
......
......@@ -87,7 +87,7 @@ pthread_setcancelstate (int state, int *oldstate)
{
int result = 0;
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
|| (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE))
......
......@@ -88,7 +88,7 @@ pthread_setcanceltype (int type, int *oldtype)
{
int result = 0;
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
if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
......
......@@ -78,7 +78,7 @@ pte_setthreadpriority (pthread_t thread, int policy, int priority)
{
int prio;
int result;
pte_thread_t * tp = (pte_thread_t *) thread.p;
pte_thread_t * tp = (pte_thread_t *) thread;
prio = priority;
......
......@@ -84,7 +84,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
* thread if one wasn't explicitly created
*/
self = pthread_self ();
if (self.p == NULL)
if (self == NULL)
{
return ENOENT;
}
......@@ -116,7 +116,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
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
......@@ -131,7 +131,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
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));
......
......@@ -75,7 +75,7 @@ pthread_testcancel (void)
*/
{
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)
{
......
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