From 851f90b1bc9c43c1443fa3bf6cd587d35a5c82b1 Mon Sep 17 00:00:00 2001 From: cgf Date: Thu, 26 Jul 2001 20:47:05 +0000 Subject: [PATCH] * thread.cc (__pthread_equal): Invert return value so that true is returned when threads are equal. --- winsup/cygwin/ChangeLog | 5 + winsup/cygwin/thread.cc | 445 ++++++++++++++++++++++++------------------------ 2 files changed, 227 insertions(+), 223 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1fe90278a3..383ea038e3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 26 16:43:39 2001 Pieter de Visser + + * thread.cc (__pthread_equal): Invert return value so that true is + returned when threads are equal. + Thu Jul 26 15:50:38 2001 Charles Wilson Christopher Faylor diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 640c9756ae..b89078c84b 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1,4 +1,4 @@ -/* thread.cc: Locking and threading module functions +/*thread.cc: Locking and threading module functions Copyright 1998, 1999, 2000, 2001 Red Hat, Inc. @@ -10,7 +10,7 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -/* Implementation overview and caveats: +/*Implementation overview and caveats: Win32 puts some contraints on what can and cannot be implemented. Where possible we work around those contrainsts. Where we cannot work around the constraints we @@ -22,7 +22,6 @@ details. */ proper operation. R.Collins, April 2001. - */ #ifdef HAVE_CONFIG_H @@ -48,12 +47,12 @@ details. */ extern int threadsafe; -/* pthread_key_destructor_list class: to-be threadsafe single linked list - * FIXME: Put me in a dedicated file, or a least a tools area ! +/*pthread_key_destructor_list class: to-be threadsafe single linked list + *FIXME: Put me in a dedicated file, or a least a tools area ! */ pthread_key_destructor * -pthread_key_destructor::InsertAfter (pthread_key_destructor * node) +pthread_key_destructor::InsertAfter (pthread_key_destructor *node) { pthread_key_destructor *temp = next; next = node; @@ -76,18 +75,18 @@ pthread_key_destructor::Next () } void -pthread_key_destructor_list::Insert (pthread_key_destructor * node) +pthread_key_destructor_list::Insert (pthread_key_destructor *node) { if (!node) return; head = node->InsertAfter (head); if (!head) - head = node; /* first node special case */ + head = node; /*first node special case */ } - /* remove a given dataitem, wherever in the list it is */ + /*remove a given dataitem, wherever in the list it is */ pthread_key_destructor * -pthread_key_destructor_list::Remove (pthread_key * key) +pthread_key_destructor_list::Remove (pthread_key *key) { if (!key) return NULL; @@ -105,7 +104,7 @@ pthread_key_destructor_list::Remove (pthread_key * key) return NULL; } - /* get the first item and remove at the same time */ + /*get the first item and remove at the same time */ pthread_key_destructor * pthread_key_destructor_list::Pop () { @@ -115,7 +114,7 @@ pthread_key_destructor_list::Pop () } pthread_key_destructor:: -pthread_key_destructor (void (*thedestructor) (void *), pthread_key * key) +pthread_key_destructor (void (*thedestructor) (void *), pthread_key *key) { destructor = thedestructor; next = NULL; @@ -293,17 +292,17 @@ MTinterface::Init (int forked) } concurrency = 0; - threadcount = 1; /* 1 current thread when Init occurs.*/ + threadcount = 1; /*1 current thread when Init occurs.*/ mainthread.win32_obj_id = myself->hProcess; mainthread.setThreadIdtoCurrent (); - /* store the main thread's self pointer */ + /*store the main thread's self pointer */ TlsSetValue (thread_self_dwTlsIndex, &mainthread); if (forked) return; - /* possible the atfork lists should be inited here as well */ + /*possible the atfork lists should be inited here as well */ for (int i = 0; i < 256; i++) pshared_mutexs[i] = NULL; @@ -330,10 +329,10 @@ pthread::~pthread () void -pthread::create (void *(*func) (void *), pthread_attr * newattr, +pthread::create (void *(*func) (void *), pthread_attr *newattr, void *threadarg) { - /* already running ? */ + /*already running ? */ if (win32_obj_id) return; @@ -355,11 +354,11 @@ pthread::create (void *(*func) (void *), pthread_attr * newattr, magic = 0; else { - /* FIXME: set the priority appropriately for system contention scope */ + /*FIXME: set the priority appropriately for system contention scope */ if (attr.inheritsched == PTHREAD_EXPLICIT_SCHED) { - /* FIXME: set the scheduling settings for the new thread */ - /* sched_thread_setparam (win32_obj_id, attr.schedparam); */ + /*FIXME: set the scheduling settings for the new thread */ + /*sched_thread_setparam (win32_obj_id, attr.schedparam); */ } ResumeThread (win32_obj_id); } @@ -385,22 +384,22 @@ pthread_condattr::~pthread_condattr () { } -pthread_cond::pthread_cond (pthread_condattr * attr):verifyable_object (PTHREAD_COND_MAGIC) +pthread_cond::pthread_cond (pthread_condattr *attr):verifyable_object (PTHREAD_COND_MAGIC) { int temperr; this->shared = attr ? attr->shared : PTHREAD_PROCESS_PRIVATE; this->mutex = NULL; this->waiting = 0; - this->win32_obj_id =::CreateEvent (&sec_none_nih, false, /* auto signal reset - which I think is pthreads like ? */ - false, /* start non signaled */ - NULL /* no name */); - /* TODO: make a shared mem mutex if out attributes request shared mem cond */ + this->win32_obj_id =::CreateEvent (&sec_none_nih, false, /*auto signal reset - which I think is pthreads like ? */ + false, /*start non signaled */ + NULL /*no name */); + /*TODO: make a shared mem mutex if out attributes request shared mem cond */ cond_access=NULL; if ((temperr = pthread_mutex_init (&this->cond_access, NULL))) { system_printf ("couldn't init mutex, this %0p errno=%d\n", this, temperr); - /* we need the mutex for correct behaviour */ + /*we need the mutex for correct behaviour */ magic = 0; } @@ -425,7 +424,7 @@ pthread_cond::BroadCast () { if (pthread_mutex_unlock (&cond_access)) system_printf ("Failed to unlock condition variable access mutex, this %0p\n", this); - /* This isn't and API error - users are allowed to call this when no threads + /*This isn't and API error - users are allowed to call this when no threads are waiting system_printf ("Broadcast called with invalid mutex\n"); */ @@ -471,12 +470,12 @@ pthread_cond::TimedWait (DWORD dwMilliseconds) switch (rv) { case WAIT_FAILED: - return 0; /* POSIX doesn't allow errors after we modify the mutex state */ + return 0; /*POSIX doesn't allow errors after we modify the mutex state */ case WAIT_ABANDONED: case WAIT_TIMEOUT: return ETIMEDOUT; case WAIT_OBJECT_0: - return 0; /* we have been signaled */ + return 0; /*we have been signaled */ default: return 0; } @@ -496,7 +495,7 @@ pthread_key::pthread_key (void (*destructor) (void *)):verifyable_object (PTHREA pthread_key::~pthread_key () { - if (pthread_key_destructor * dest = MT_INTERFACE->destructors.Remove (this)) + if (pthread_key_destructor *dest = MT_INTERFACE->destructors.Remove (this)) delete dest; TlsFree (dwTlsIndex); } @@ -504,7 +503,7 @@ pthread_key::~pthread_key () int pthread_key::set (const void *value) { - /* the OS function doesn't perform error checking */ + /*the OS function doesn't perform error checking */ TlsSetValue (dwTlsIndex, (void *) value); return 0; } @@ -526,24 +525,24 @@ typedef struct _pshared_mutex { unsigned char flags; } pshared_mutex; -/* pshared mutexs: - * the mutex_t (size 4) is not used as a verifyable object because we cannot - * guarantee the same address space for all processes. - * we use the following: - * high bit set (never a valid address). - * second byte is reserved for the priority. - * third byte is reserved - * fourth byte is the mutex id. (max 255 cygwin mutexs system wide). - * creating mutex's does get slower and slower, but as creation is a one time - * job, it should never become an issue +/*pshared mutexs: + *the mutex_t (size 4) is not used as a verifyable object because we cannot + *guarantee the same address space for all processes. + *we use the following: + *high bit set (never a valid address). + *second byte is reserved for the priority. + *third byte is reserved + *fourth byte is the mutex id. (max 255 cygwin mutexs system wide). + *creating mutex's does get slower and slower, but as creation is a one time + *job, it should never become an issue * - * And if you're looking at this and thinking, why not an array in cygwin for all mutexs, - * - you incur a penalty on _every_ mutex call and you have toserialise them all. - * ... Bad karma. + *And if you're looking at this and thinking, why not an array in cygwin for all mutexs, + *- you incur a penalty on _every_ mutex call and you have toserialise them all. + *... Bad karma. * - * option 2? put everything in userspace and update the ABI? - * - bad karma as well - the HANDLE, while identical across process's, - * Isn't duplicated, it's reopened. + *option 2? put everything in userspace and update the ABI? + *- bad karma as well - the HANDLE, while identical across process's, + *Isn't duplicated, it's reopened. */ pthread_mutex::pthread_mutex (unsigned short id):verifyable_object (PTHREAD_MUTEX_MAGIC) @@ -571,9 +570,9 @@ pthread_mutex::pthread_mutex (unsigned short id):verifyable_object (PTHREAD_MUTE MT_INTERFACE->pshared_mutexs[id] = this; } -pthread_mutex::pthread_mutex (pthread_mutex_t *mutex, pthread_mutexattr * attr):verifyable_object (PTHREAD_MUTEX_MAGIC) +pthread_mutex::pthread_mutex (pthread_mutex_t *mutex, pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC) { - /* attr checked in the C call */ + /*attr checked in the C call */ if (attr && attr->pshared==PTHREAD_PROCESS_SHARED) { //FIXME: set an appropriate security mask - probably everyone. @@ -613,12 +612,12 @@ pthread_mutex::pthread_mutex (pthread_mutex_t *mutex, pthread_mutexattr * attr): } } -pthread_mutex::pthread_mutex (pthread_mutexattr * attr):verifyable_object (PTHREAD_MUTEX_MAGIC) +pthread_mutex::pthread_mutex (pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC) { - /* attr checked in the C call */ + /*attr checked in the C call */ if (attr && attr->pshared==PTHREAD_PROCESS_SHARED) { - /* for pshared mutex's we need the mutex address */ + /*for pshared mutex's we need the mutex address */ magic = 0; return; } @@ -664,8 +663,8 @@ __pthread_mutex_getpshared (pthread_mutex_t *mutex) pshared_mutex *pmutex=(pshared_mutex *)(mutex); if ((MT_INTERFACE->pshared_mutexs[pmutex->id]) != NULL) return &(MT_INTERFACE->pshared_mutexs[pmutex->id]); - /* attempt to get the existing mutex */ - pthread_mutex * newmutex; + /*attempt to get the existing mutex */ + pthread_mutex *newmutex; newmutex = new pthread_mutex (pmutex->id); if (!verifyable_object_isvalid (newmutex, PTHREAD_MUTEX_MAGIC)) { @@ -710,8 +709,8 @@ semaphore::Post () int semaphore::TryWait () { - /* FIXME: signals should be able to interrupt semaphores... - * We probably need WaitForMultipleObjects here. + /*FIXME: signals should be able to interrupt semaphores... + *We probably need WaitForMultipleObjects here. */ if (WaitForSingleObject (win32_obj_id, 0) == WAIT_TIMEOUT) return EAGAIN; @@ -735,7 +734,7 @@ verifyable_object::~verifyable_object () magic = 0; } -/* Generic memory acccess routine - where should it live ? */ +/*Generic memory acccess routine - where should it live ? */ int __stdcall check_valid_pointer (void *pointer) { @@ -745,7 +744,7 @@ check_valid_pointer (void *pointer) } int -verifyable_object_isvalid (verifyable_object * object, long magic) +verifyable_object_isvalid (verifyable_object *object, long magic) { if (!object || object == PTHREAD_MUTEX_INITIALIZER) return 0; @@ -756,7 +755,7 @@ verifyable_object_isvalid (verifyable_object * object, long magic) return -1; } -/* Pthreads */ +/* Pthreads */ void * thread_init_wrapper (void *_arg) { @@ -768,7 +767,7 @@ thread_init_wrapper (void *_arg) struct _reent local_clib = _REENT_INIT(local_clib); struct sigaction _sigs[NSIG]; - sigset_t _sig_mask; /* one set for everything to ignore. */ + sigset_t _sig_mask; /*one set for everything to ignore. */ LONG _sigtodo[NSIG + __SIGOFFSET]; // setup signal structures @@ -783,11 +782,11 @@ thread_init_wrapper (void *_arg) local_winsup._process_logmask = LOG_UPTO (LOG_DEBUG); - /* This is not checked by the OS !! */ + /*This is not checked by the OS !! */ if (!TlsSetValue (MT_INTERFACE->reent_index, &local_reent)) system_printf ("local storage for thread couldn't be set"); - /* the OS doesn't check this for <=64 Tls entries (pre win2k) */ + /*the OS doesn't check this for <=64 Tls entries (pre win2k) */ TlsSetValue (MT_INTERFACE->thread_self_dwTlsIndex, thread); #ifdef _CYG_THREAD_FAILSAFE @@ -807,12 +806,12 @@ thread_init_wrapper (void *_arg) // ??? This code only runs if the thread exits by returning. // it's all now in __pthread_exit (); #endif - /* never reached */ + /*never reached */ return 0; } int -__pthread_create (pthread_t * thread, const pthread_attr_t * attr, +__pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { if (attr && !verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) @@ -832,29 +831,29 @@ __pthread_create (pthread_t * thread, const pthread_attr_t * attr, } int -__pthread_once (pthread_once_t * once_control, void (*init_routine) (void)) +__pthread_once (pthread_once_t *once_control, void (*init_routine) (void)) { pthread_mutex_lock (&once_control->mutex); - /* Here we must set a cancellation handler to unlock the mutex if needed */ - /* but a cancellation handler is not the right thing. We need this in the thread - * cleanup routine. Assumption: a thread can only be in one pthread_once routine - * at a time. Stote a mutex_t * in the pthread_structure. if that's non null unlock - * on pthread_exit (); + /*Here we must set a cancellation handler to unlock the mutex if needed */ + /*but a cancellation handler is not the right thing. We need this in the thread + *cleanup routine. Assumption: a thread can only be in one pthread_once routine + *at a time. Stote a mutex_t *in the pthread_structure. if that's non null unlock + *on pthread_exit (); */ if (once_control->state == 0) { init_routine (); once_control->state = 1; } - /* Here we must remove our cancellation handler */ + /*Here we must remove our cancellation handler */ pthread_mutex_unlock (&once_control->mutex); return 0; } -/* Cancelability states */ +/*Cancelability states */ -/* Perform the actual cancel */ +/*Perform the actual cancel */ void __pthread_cleanup (pthread_t thread) { @@ -869,21 +868,21 @@ __pthread_cancel (pthread_t thread) if (thread->cancelstate == PTHREAD_CANCEL_ENABLE) { #if 0 - /* once all the functions call testcancel (), we will do this */ + /*once all the functions call testcancel (), we will do this */ if (thread->canceltype == PTHREAD_CANCEL_DEFERRED) { } else { - /* possible FIXME: this function is meant to return asynchronously - * from the cancellation routine actually firing. So we may need some sort - * of signal to be sent that is immediately recieved and acted on. + /*possible FIXME: this function is meant to return asynchronously + *from the cancellation routine actually firing. So we may need some sort + *of signal to be sent that is immediately recieved and acted on. */ __pthread_cleanup (thread); } #endif } -/* return 0; +/* return 0; */ return ESRCH; @@ -891,7 +890,7 @@ __pthread_cancel (pthread_t thread) we return ESRCH until all the required functions call testcancel (); this will give applications predictable behaviour. - the required function list is: * indicates done, X indicates not present in cygwin. + the required function list is: *indicates done, X indicates not present in cygwin. aio_suspend () *close () *creat () @@ -995,10 +994,10 @@ getgrnam_r () getlogin () getlogin_r () getpwent () -* getpwnam () -* getpwnam_r () -* getpwuid () -* getpwuid_r () +*getpwnam () +*getpwnam_r () +*getpwuid () +*getpwuid_r () gets () getutxent () getutxid () @@ -1064,7 +1063,7 @@ opengroup specs. */ } -/* no races in these three functions: they are all current-thread-only */ +/*no races in these three functions: they are all current-thread-only */ int __pthread_setcancelstate (int state, int *oldstate) { @@ -1087,34 +1086,34 @@ __pthread_setcanceltype (int type, int *oldtype) return 0; } -/* deferred cancellation request handler */ +/*deferred cancellation request handler */ void __pthread_testcancel (void) { class pthread *thread = __pthread_self (); if (thread->cancelstate == PTHREAD_CANCEL_DISABLE) return; - /* check the cancellation event object here - not neededuntil pthread_cancel actually - * does something*/ + /*check the cancellation event object here - not neededuntil pthread_cancel actually + *does something*/ } /* - * Races in pthread_atfork: - * We are race safe in that any additions to the lists are made via - * InterlockedExchangePointer. - * However, if the user application doesn't perform syncronisation of some sort - * It's not guaranteed that a near simultaneous call to pthread_atfork and fork - * will result in the new atfork handlers being calls. - * More rigorous internal syncronisation isn't needed as the user program isn't - * guaranteeing their own state. + *Races in pthread_atfork: + *We are race safe in that any additions to the lists are made via + *InterlockedExchangePointer. + *However, if the user application doesn't perform syncronisation of some sort + *It's not guaranteed that a near simultaneous call to pthread_atfork and fork + *will result in the new atfork handlers being calls. + *More rigorous internal syncronisation isn't needed as the user program isn't + *guaranteeing their own state. * - * as far as multiple calls to pthread_atfork, the worst case is simultaneous calls - * will result in an indeterminate order for parent and child calls (what gets inserted - * first isn't guaranteed.) + *as far as multiple calls to pthread_atfork, the worst case is simultaneous calls + *will result in an indeterminate order for parent and child calls (what gets inserted + *first isn't guaranteed.) * - * There is one potential race... Does the result of InterlockedExchangePointer - * get committed to the return location _before_ any context switches can occur? - * If yes, we're safe, if no, we're not. + *There is one potential race... Does the result of InterlockedExchangePointer + *get committed to the return location _before_ any context switches can occur? + *If yes, we're safe, if no, we're not. */ void __pthread_atforkprepare (void) @@ -1149,18 +1148,18 @@ __pthread_atforkchild (void) } } -/* FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below +/*FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below */ #define InterlockedExchangePointer InterlockedExchange -/* Register a set of functions to run before and after fork. - * prepare calls are called in LI-FC order. - * parent and child calls are called in FI-FC order. +/*Register a set of functions to run before and after fork. + *prepare calls are called in LI-FC order. + *parent and child calls are called in FI-FC order. */ int __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void)) { - callback * prepcb = NULL, * parentcb = NULL, * childcb = NULL; + callback *prepcb = NULL, *parentcb = NULL, *childcb = NULL; if (prepare) { prepcb = new callback; @@ -1198,26 +1197,26 @@ __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(voi if (parentcb) { parentcb->cb = parent; - callback ** t = &MT_INTERFACE->pthread_parent; + callback **t = &MT_INTERFACE->pthread_parent; while (*t) t = &(*t)->next; - /* t = pointer to last next in the list */ + /*t = pointer to last next in the list */ parentcb->next=(callback *)InterlockedExchangePointer ((LONG *) t, (long int) parentcb); } if (childcb) { childcb->cb = child; - callback ** t = &MT_INTERFACE->pthread_child; + callback **t = &MT_INTERFACE->pthread_child; while (*t) t = &(*t)->next; - /* t = pointer to last next in the list */ + /*t = pointer to last next in the list */ childcb->next=(callback *)InterlockedExchangePointer ((LONG *) t, (long int) childcb); } return 0; } int -__pthread_attr_init (pthread_attr_t * attr) +__pthread_attr_init (pthread_attr_t *attr) { *attr = new pthread_attr; if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) @@ -1230,7 +1229,7 @@ __pthread_attr_init (pthread_attr_t * attr) } int -__pthread_attr_getinheritsched (const pthread_attr_t * attr, +__pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inheritsched) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) @@ -1240,7 +1239,7 @@ __pthread_attr_getinheritsched (const pthread_attr_t * attr, } int -__pthread_attr_getschedparam (const pthread_attr_t * attr, +__pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) @@ -1249,12 +1248,12 @@ __pthread_attr_getschedparam (const pthread_attr_t * attr, return 0; } -/* From a pure code point of view, this should call a helper in sched.cc, - * to allow for someone adding scheduler policy changes to win32 in the future. - * However that's extremely unlikely, so short and sweet will do us +/*From a pure code point of view, this should call a helper in sched.cc, + *to allow for someone adding scheduler policy changes to win32 in the future. + *However that's extremely unlikely, so short and sweet will do us */ int -__pthread_attr_getschedpolicy (const pthread_attr_t * attr, int *policy) +__pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1264,7 +1263,7 @@ __pthread_attr_getschedpolicy (const pthread_attr_t * attr, int *policy) int -__pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope) +__pthread_attr_getscope (const pthread_attr_t *attr, int *contentionscope) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1273,7 +1272,7 @@ __pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope) } int -__pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate) +__pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1284,7 +1283,7 @@ __pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate) } int -__pthread_attr_getdetachstate (const pthread_attr_t * attr, int *detachstate) +__pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1293,7 +1292,7 @@ __pthread_attr_getdetachstate (const pthread_attr_t * attr, int *detachstate) } int -__pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched) +__pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1305,7 +1304,7 @@ __pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched) } int -__pthread_attr_setschedparam (pthread_attr_t * attr, +__pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) @@ -1316,9 +1315,9 @@ __pthread_attr_setschedparam (pthread_attr_t * attr, return 0; } -/* See __pthread_attr_getschedpolicy for some notes */ +/*See __pthread_attr_getschedpolicy for some notes */ int -__pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy) +__pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1328,15 +1327,15 @@ __pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy) } int -__pthread_attr_setscope (pthread_attr_t * attr, int contentionscope) +__pthread_attr_setscope (pthread_attr_t *attr, int contentionscope) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; if (contentionscope != PTHREAD_SCOPE_SYSTEM && contentionscope != PTHREAD_SCOPE_PROCESS) return EINVAL; - /* In future, we may be able to support system scope by escalating the thread - * priority to exceed the priority class. For now we only support PROCESS scope. */ + /*In future, we may be able to support system scope by escalating the thread + *priority to exceed the priority class. For now we only support PROCESS scope. */ if (contentionscope != PTHREAD_SCOPE_PROCESS) return ENOTSUP; (*attr)->contentionscope = contentionscope; @@ -1344,7 +1343,7 @@ __pthread_attr_setscope (pthread_attr_t * attr, int contentionscope) } int -__pthread_attr_setstacksize (pthread_attr_t * attr, size_t size) +__pthread_attr_setstacksize (pthread_attr_t *attr, size_t size) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1353,7 +1352,7 @@ __pthread_attr_setstacksize (pthread_attr_t * attr, size_t size) } int -__pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * size) +__pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1362,7 +1361,7 @@ __pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * size) } int -__pthread_attr_destroy (pthread_attr_t * attr) +__pthread_attr_destroy (pthread_attr_t *attr) { if (!verifyable_object_isvalid (*attr, PTHREAD_ATTR_MAGIC)) return EINVAL; @@ -1386,9 +1385,9 @@ __pthread_exit (void *value_ptr) } int -__pthread_join (pthread_t * thread, void **return_val) +__pthread_join (pthread_t *thread, void **return_val) { - /* FIXME: wait on the thread cancellation event as well - we are a cancellation point*/ + /*FIXME: wait on the thread cancellation event as well - we are a cancellation point*/ if (!verifyable_object_isvalid (*thread, PTHREAD_MAGIC)) return ESRCH; @@ -1404,7 +1403,7 @@ __pthread_join (pthread_t * thread, void **return_val) WaitForSingleObject ((*thread)->win32_obj_id, INFINITE); if (return_val) *return_val = (*thread)->return_ptr; - } /* End if */ + } /*End if */ pthread_testcancel (); @@ -1412,7 +1411,7 @@ __pthread_join (pthread_t * thread, void **return_val) } int -__pthread_detach (pthread_t * thread) +__pthread_detach (pthread_t *thread) { if (!verifyable_object_isvalid (*thread, PTHREAD_MAGIC)) return ESRCH; @@ -1428,7 +1427,7 @@ __pthread_detach (pthread_t * thread) } int -__pthread_suspend (pthread_t * thread) +__pthread_suspend (pthread_t *thread) { if (!verifyable_object_isvalid (*thread, PTHREAD_MAGIC)) return ESRCH; @@ -1444,7 +1443,7 @@ __pthread_suspend (pthread_t * thread) int -__pthread_continue (pthread_t * thread) +__pthread_continue (pthread_t *thread) { if (!verifyable_object_isvalid (*thread, PTHREAD_MAGIC)) return ESRCH; @@ -1456,8 +1455,8 @@ __pthread_continue (pthread_t * thread) return 0; } -/* provided for source level compatability. - * See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html +/*provided for source level compatability. + *See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html */ int __pthread_getconcurrency (void) @@ -1465,7 +1464,7 @@ __pthread_getconcurrency (void) return MT_INTERFACE->concurrency; } -/* keep this in sync with sched.cc */ +/*keep this in sync with sched.cc */ int __pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param) @@ -1473,27 +1472,27 @@ __pthread_getschedparam (pthread_t thread, int *policy, if (!verifyable_object_isvalid (thread, PTHREAD_MAGIC)) return ESRCH; *policy = SCHED_FIFO; - /* we don't return the current effective priority, we return the current requested - * priority */ + /*we don't return the current effective priority, we return the current requested + *priority */ *param = thread->attr.schedparam; return 0; } unsigned long -__pthread_getsequence_np (pthread_t * thread) +__pthread_getsequence_np (pthread_t *thread) { if (!verifyable_object_isvalid (*thread, PTHREAD_MAGIC)) return EINVAL; return (*thread)->GetThreadId (); } -/* Thread SpecificData */ +/*Thread SpecificData */ int -__pthread_key_create (pthread_key_t * key, void (*destructor) (void *)) +__pthread_key_create (pthread_key_t *key, void (*destructor) (void *)) { - /* The opengroup docs don't define if we should check this or not, - * but creation is relatively rare.. + /*The opengroup docs don't define if we should check this or not, + *but creation is relatively rare.. */ if (verifyable_object_isvalid (*key, PTHREAD_KEY_MAGIC)) return EBUSY; @@ -1519,8 +1518,8 @@ __pthread_key_delete (pthread_key_t key) return 0; } -/* provided for source level compatability. - * See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html +/*provided for source level compatability. + *See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html */ int __pthread_setconcurrency (int new_level) @@ -1531,7 +1530,7 @@ __pthread_setconcurrency (int new_level) return 0; } -/* keep syncronised with sched.cc */ +/*keep syncronised with sched.cc */ int __pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param) @@ -1569,15 +1568,15 @@ __pthread_getspecific (pthread_key_t key) } -/* Thread synchronisation */ +/*Thread synchronisation */ int -__pthread_cond_destroy (pthread_cond_t * cond) +__pthread_cond_destroy (pthread_cond_t *cond) { if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC)) return EINVAL; - /* reads are atomic */ + /*reads are atomic */ if ((*cond)->waiting) return EBUSY; @@ -1588,7 +1587,7 @@ __pthread_cond_destroy (pthread_cond_t * cond) } int -__pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr) +__pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) { if (attr && !verifyable_object_isvalid (*attr, PTHREAD_CONDATTR_MAGIC)) return EINVAL; @@ -1609,7 +1608,7 @@ __pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr) } int -__pthread_cond_broadcast (pthread_cond_t * cond) +__pthread_cond_broadcast (pthread_cond_t *cond) { if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC)) return EINVAL; @@ -1620,7 +1619,7 @@ __pthread_cond_broadcast (pthread_cond_t * cond) } int -__pthread_cond_signal (pthread_cond_t * cond) +__pthread_cond_signal (pthread_cond_t *cond) { if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC)) return EINVAL; @@ -1633,7 +1632,7 @@ __pthread_cond_signal (pthread_cond_t * cond) // FIXME: pshared mutexs have the cond count in the shared memory area. // We need to accomodate that. int -__pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, +__pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { // and yes cond_access here is still open to a race. (we increment, context swap, @@ -1657,11 +1656,11 @@ __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, struct timeb currSysTime; long waitlength; ftime(&currSysTime); - waitlength = (abstime->tv_sec - currSysTime.time) * 1000; + waitlength = (abstime->tv_sec - currSysTime.time) *1000; if (waitlength < 0) return ETIMEDOUT; - /* if the cond variable is blocked, then the above timer test maybe wrong. *shrug* */ + /*if the cond variable is blocked, then the above timer test maybe wrong. *shrug**/ if (pthread_mutex_lock (&(*cond)->cond_access)) system_printf ("Failed to lock condition variable access mutex, this %0p\n", *cond); @@ -1692,7 +1691,7 @@ __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, } int -__pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex) +__pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) { // see cond_timedwait for notes int rv; @@ -1738,7 +1737,7 @@ __pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex) } int -__pthread_condattr_init (pthread_condattr_t * condattr) +__pthread_condattr_init (pthread_condattr_t *condattr) { *condattr = new pthread_condattr; if (!verifyable_object_isvalid (*condattr, PTHREAD_CONDATTR_MAGIC)) @@ -1751,7 +1750,7 @@ __pthread_condattr_init (pthread_condattr_t * condattr) } int -__pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared) +__pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared) { if (!verifyable_object_isvalid (*attr, PTHREAD_CONDATTR_MAGIC)) return EINVAL; @@ -1760,13 +1759,13 @@ __pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared) } int -__pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared) +__pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared) { if (!verifyable_object_isvalid (*attr, PTHREAD_CONDATTR_MAGIC)) return EINVAL; if ((pshared < 0) || (pshared > 1)) return EINVAL; - /* shared cond vars not currently supported */ + /*shared cond vars not currently supported */ if (pshared != PTHREAD_PROCESS_PRIVATE) return EINVAL; (*attr)->shared = pshared; @@ -1774,7 +1773,7 @@ __pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared) } int -__pthread_condattr_destroy (pthread_condattr_t * condattr) +__pthread_condattr_destroy (pthread_condattr_t *condattr) { if (!verifyable_object_isvalid (*condattr, PTHREAD_CONDATTR_MAGIC)) return EINVAL; @@ -1783,7 +1782,7 @@ __pthread_condattr_destroy (pthread_condattr_t * condattr) return 0; } -/* Thread signal */ +/*Thread signal */ int __pthread_kill (pthread_t thread, int sig) { @@ -1803,7 +1802,7 @@ __pthread_kill (pthread_t thread, int sig) } int -__pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set) +__pthread_sigmask (int operation, const sigset_t *set, sigset_t *old_set) { pthread *thread = __pthread_self (); @@ -1820,7 +1819,7 @@ __pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set) return rval; } -/* ID */ +/* ID */ pthread_t __pthread_self () { @@ -1828,25 +1827,25 @@ __pthread_self () } int -__pthread_equal (pthread_t * t1, pthread_t * t2) +__pthread_equal (pthread_t *t1, pthread_t *t2) { - return (*t1 - *t2); + return (*t1 == *t2); } -/* Mutexes */ +/*Mutexes */ -/* FIXME: there's a potential race with PTHREAD_MUTEX_INITALIZER: - * the mutex is not actually inited until the first use. - * So two threads trying to lock/trylock may collide. - * Solution: we need a global mutex on mutex creation, or possibly simply - * on all constructors that allow INITIALIZER macros. - * the lock should be very small: only around the init routine, not - * every test, or all mutex access will be synchronised. +/*FIXME: there's a potential race with PTHREAD_MUTEX_INITALIZER: + *the mutex is not actually inited until the first use. + *So two threads trying to lock/trylock may collide. + *Solution: we need a global mutex on mutex creation, or possibly simply + *on all constructors that allow INITIALIZER macros. + *the lock should be very small: only around the init routine, not + *every test, or all mutex access will be synchronised. */ int -__pthread_mutex_init (pthread_mutex_t * mutex, - const pthread_mutexattr_t * attr) +__pthread_mutex_init (pthread_mutex_t *mutex, + const pthread_mutexattr_t *attr) { if ((((pshared_mutex *)(mutex))->flags & SYS_BASE == SYS_BASE)) // a pshared mutex @@ -1881,7 +1880,7 @@ __pthread_mutex_init (pthread_mutex_t * mutex, } int -__pthread_mutex_getprioceiling (const pthread_mutex_t * mutex, +__pthread_mutex_getprioceiling (const pthread_mutex_t *mutex, int *prioceiling) { pthread_mutex_t *themutex=(pthread_mutex_t *) mutex; @@ -1892,19 +1891,19 @@ __pthread_mutex_getprioceiling (const pthread_mutex_t * mutex, themutex = __pthread_mutex_getpshared ((pthread_mutex_t *) mutex); if (!verifyable_object_isvalid (*themutex, PTHREAD_MUTEX_MAGIC)) return EINVAL; - /* We don't define _POSIX_THREAD_PRIO_PROTECT because we do't currently support - * mutex priorities. + /*We don't define _POSIX_THREAD_PRIO_PROTECT because we do't currently support + *mutex priorities. * - * We can support mutex priorities in the future though: - * Store a priority with each mutex. - * When the mutex is optained, set the thread priority as appropriate - * When the mutex is released, reset the thre priority. + *We can support mutex priorities in the future though: + *Store a priority with each mutex. + *When the mutex is optained, set the thread priority as appropriate + *When the mutex is released, reset the thre priority. */ return ENOSYS; } int -__pthread_mutex_lock (pthread_mutex_t * mutex) +__pthread_mutex_lock (pthread_mutex_t *mutex) { pthread_mutex_t *themutex = mutex; if (*mutex == PTHREAD_MUTEX_INITIALIZER) @@ -1919,7 +1918,7 @@ __pthread_mutex_lock (pthread_mutex_t * mutex) } int -__pthread_mutex_trylock (pthread_mutex_t * mutex) +__pthread_mutex_trylock (pthread_mutex_t *mutex) { pthread_mutex_t *themutex = mutex; if (*mutex == PTHREAD_MUTEX_INITIALIZER) @@ -1935,7 +1934,7 @@ __pthread_mutex_trylock (pthread_mutex_t * mutex) } int -__pthread_mutex_unlock (pthread_mutex_t * mutex) +__pthread_mutex_unlock (pthread_mutex_t *mutex) { if (*mutex == PTHREAD_MUTEX_INITIALIZER) __pthread_mutex_init (mutex, NULL); @@ -1949,7 +1948,7 @@ __pthread_mutex_unlock (pthread_mutex_t * mutex) } int -__pthread_mutex_destroy (pthread_mutex_t * mutex) +__pthread_mutex_destroy (pthread_mutex_t *mutex) { if (*mutex == PTHREAD_MUTEX_INITIALIZER) return 0; @@ -1959,7 +1958,7 @@ __pthread_mutex_destroy (pthread_mutex_t * mutex) if (!verifyable_object_isvalid (*mutex, PTHREAD_MUTEX_MAGIC)) return EINVAL; - /* reading a word is atomic */ + /*reading a word is atomic */ if ((*mutex)->condwaits) return EBUSY; @@ -1969,7 +1968,7 @@ __pthread_mutex_destroy (pthread_mutex_t * mutex) } int -__pthread_mutex_setprioceiling (pthread_mutex_t * mutex, int prioceiling, +__pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling, int *old_ceiling) { pthread_mutex_t *themutex = mutex; @@ -1983,10 +1982,10 @@ __pthread_mutex_setprioceiling (pthread_mutex_t * mutex, int prioceiling, return ENOSYS; } -/* Win32 doesn't support mutex priorities - see __pthread_mutex_getprioceiling - * for more detail */ +/*Win32 doesn't support mutex priorities - see __pthread_mutex_getprioceiling + *for more detail */ int -__pthread_mutexattr_getprotocol (const pthread_mutexattr_t * attr, +__pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEX_MAGIC)) @@ -1995,7 +1994,7 @@ __pthread_mutexattr_getprotocol (const pthread_mutexattr_t * attr, } int -__pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, +__pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr, int *pshared) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEX_MAGIC)) @@ -2004,12 +2003,12 @@ __pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, return 0; } -/* Win32 mutex's are equivalent to posix RECURSIVE mutexs. - * We need to put glue in place to support other types of mutex's. We map - * PTHREAD_MUTEX_DEFAULT to PTHREAD_MUTEX_RECURSIVE and return EINVAL for other types. +/*Win32 mutex's are equivalent to posix RECURSIVE mutexs. + *We need to put glue in place to support other types of mutex's. We map + *PTHREAD_MUTEX_DEFAULT to PTHREAD_MUTEX_RECURSIVE and return EINVAL for other types. */ int -__pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *type) +__pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEX_MAGIC)) return EINVAL; @@ -2017,13 +2016,13 @@ __pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *type) return 0; } -/* Currently pthread_mutex_init ignores the attr variable, this is because - * none of the variables have any impact on it's behaviour. +/*Currently pthread_mutex_init ignores the attr variable, this is because + *none of the variables have any impact on it's behaviour. * - * FIXME: write and test process shared mutex's. + *FIXME: write and test process shared mutex's. */ int -__pthread_mutexattr_init (pthread_mutexattr_t * attr) +__pthread_mutexattr_init (pthread_mutexattr_t *attr) { if (verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) return EBUSY; @@ -2039,7 +2038,7 @@ __pthread_mutexattr_init (pthread_mutexattr_t * attr) } int -__pthread_mutexattr_destroy (pthread_mutexattr_t * attr) +__pthread_mutexattr_destroy (pthread_mutexattr_t *attr) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) return EINVAL; @@ -2049,18 +2048,18 @@ __pthread_mutexattr_destroy (pthread_mutexattr_t * attr) } -/* Win32 doesn't support mutex priorities */ +/*Win32 doesn't support mutex priorities */ int -__pthread_mutexattr_setprotocol (pthread_mutexattr_t * attr, int protocol) +__pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) return EINVAL; return ENOSYS; } -/* Win32 doesn't support mutex priorities */ +/*Win32 doesn't support mutex priorities */ int -__pthread_mutexattr_setprioceiling (pthread_mutexattr_t * attr, +__pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr, int prioceiling) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) @@ -2069,7 +2068,7 @@ __pthread_mutexattr_setprioceiling (pthread_mutexattr_t * attr, } int -__pthread_mutexattr_getprioceiling (const pthread_mutexattr_t * attr, +__pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr, int *prioceiling) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) @@ -2078,12 +2077,12 @@ __pthread_mutexattr_getprioceiling (const pthread_mutexattr_t * attr, } int -__pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared) +__pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) return EINVAL; - /* we don't use pshared for anything as yet. We need to test PROCESS_SHARED - * functionality + /*we don't use pshared for anything as yet. We need to test PROCESS_SHARED + *functionality */ if (pshared != PTHREAD_PROCESS_PRIVATE && pshared != PTHREAD_PROCESS_SHARED) return EINVAL; @@ -2091,9 +2090,9 @@ __pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared) return 0; } -/* see __pthread_mutex_gettype */ +/*see __pthread_mutex_gettype */ int -__pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type) +__pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) { if (!verifyable_object_isvalid (*attr, PTHREAD_MUTEXATTR_MAGIC)) return EINVAL; @@ -2103,11 +2102,11 @@ __pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type) return 0; } -/* Semaphores */ +/*Semaphores */ int -__sem_init (sem_t * sem, int pshared, unsigned int value) +__sem_init (sem_t *sem, int pshared, unsigned int value) { - /* opengroup calls this undefined */ + /*opengroup calls this undefined */ if (verifyable_object_isvalid (*sem, SEM_MAGIC)) return EBUSY; @@ -2126,12 +2125,12 @@ __sem_init (sem_t * sem, int pshared, unsigned int value) } int -__sem_destroy (sem_t * sem) +__sem_destroy (sem_t *sem) { if (!verifyable_object_isvalid (*sem, SEM_MAGIC)) return EINVAL; - /* FIXME - new feature - test for busy against threads... */ + /*FIXME - new feature - test for busy against threads... */ delete (*sem); *sem = NULL; @@ -2139,7 +2138,7 @@ __sem_destroy (sem_t * sem) } int -__sem_wait (sem_t * sem) +__sem_wait (sem_t *sem) { if (!verifyable_object_isvalid (*sem, SEM_MAGIC)) return EINVAL; @@ -2149,7 +2148,7 @@ __sem_wait (sem_t * sem) } int -__sem_trywait (sem_t * sem) +__sem_trywait (sem_t *sem) { if (!verifyable_object_isvalid (*sem, SEM_MAGIC)) return EINVAL; @@ -2158,7 +2157,7 @@ __sem_trywait (sem_t * sem) } int -__sem_post (sem_t * sem) +__sem_post (sem_t *sem) { if (!verifyable_object_isvalid (*sem, SEM_MAGIC)) return EINVAL; -- 2.11.0