aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hotmail.com>2002-09-20 22:34:05 +0000
committerRobert Collins <rbtcollins@hotmail.com>2002-09-20 22:34:05 +0000
commit4e2822f160ec6f61d7bae8cabb4b5daad73e3f99 (patch)
tree9bdb2b552539dba326156ad748b72b4b0108c9df /winsup
parent1e0e64c9d84785830a384dbf2d6c70a1bea9d3c8 (diff)
downloadnewlib-4e2822f160ec6f61d7bae8cabb4b5daad73e3f99.zip
newlib-4e2822f160ec6f61d7bae8cabb4b5daad73e3f99.tar.gz
newlib-4e2822f160ec6f61d7bae8cabb4b5daad73e3f99.tar.bz2
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
* thread.cc: Change verifyable_object_isvalid calls with PTHREAD_MUTEX_MAGIC and PTHREAD_KEY_MAGIC and PTHREAD_ATTR_MAGIC to ::isGoodObject() calls throughout. (MTinterface::Init): Remove dead code. (pthread_attr::isGoodObject): Implement. (pthread_key::isGoodObject): Implement. (pthread_mutex::isGoodObject): Implement. (pthread_mutex::isGoodInitializerOrObject): Implement. (pthread::isGoodObject): Update signature. * thread.h (pthread_key::isGoodObject): Declare. (pthread_attr::isGoodObject): Ditto. (pthread_mutex::isGoodObject): Ditto. (pthread_mutex::isGoodInitializerOrObject): Ditto. (pthread::isGoodObject): Change to a const parameter for const correctness. (pthread_mutexattr::isGoodObject): Declare. (pthread_condattr::isGoodObject): Ditto. (pthread_cond::isGoodObject): Ditto. (semaphore::isGoodObject): Ditto.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog22
-rw-r--r--winsup/cygwin/thread.cc128
-rw-r--r--winsup/cygwin/thread.h10
3 files changed, 99 insertions, 61 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 9915b3c..ea59f61 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,25 @@
+2002-09-21 Robert Collins <rbtcollins@hotmail.com>
+
+ * thread.cc: Change verifyable_object_isvalid calls with
+ PTHREAD_MUTEX_MAGIC and PTHREAD_KEY_MAGIC and PTHREAD_ATTR_MAGIC to
+ ::isGoodObject() calls throughout.
+ (MTinterface::Init): Remove dead code.
+ (pthread_attr::isGoodObject): Implement.
+ (pthread_key::isGoodObject): Implement.
+ (pthread_mutex::isGoodObject): Implement.
+ (pthread_mutex::isGoodInitializerOrObject): Implement.
+ (pthread::isGoodObject): Update signature.
+ * thread.h (pthread_key::isGoodObject): Declare.
+ (pthread_attr::isGoodObject): Ditto.
+ (pthread_mutex::isGoodObject): Ditto.
+ (pthread_mutex::isGoodInitializerOrObject): Ditto.
+ (pthread::isGoodObject): Change to a const parameter for const
+ correctness.
+ (pthread_mutexattr::isGoodObject): Declare.
+ (pthread_condattr::isGoodObject): Ditto.
+ (pthread_cond::isGoodObject): Ditto.
+ (semaphore::isGoodObject): Ditto.
+
2002-09-19 Christopher Faylor <cgf@redhat.com>
Cleanup calls to CreateFile throughout.
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index ce0ee04..d54cc68 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -252,35 +252,16 @@ ResourceLocks::Delete ()
void
MTinterface::Init (int forked)
{
-#if 0
- for (int i = 0; i < MT_MAX_ITEMS; i++)
- {
- threadlist.items[i] = NULL;
- mutexlist.items[i] = NULL;
- semalist.items[i] = NULL;
- }
-
- threadlist.index = 0;
- mutexlist.index = 0;
- semalist.index = 0;
-#endif
reent_index = TlsAlloc ();
reents._clib = _impure_ptr;
reents._winsup = &winsup_reent;
winsup_reent._process_logmask = LOG_UPTO (LOG_DEBUG);
-#if 0
- winsup_reent._grp_pos = 0;
- winsup_reent._process_ident = 0;
- winsup_reent._process_logopt = 0;
- winsup_reent._process_facility = 0;
-#endif
TlsSetValue (reent_index, &reents);
// the static reent_data will be used in the main thread
-
if (!indexallocated)
{
thread_self_dwTlsIndex = TlsAlloc ();
@@ -303,15 +284,6 @@ MTinterface::Init (int forked)
conds = NULL;
semaphores = NULL;
- /*possible the atfork lists should be inited here as well */
-
-#if 0
- item->function = NULL;
-
- item->sigs = NULL;
- item->sigmask = NULL;
- item->sigtodo = NULL;
-#endif
}
void
@@ -422,7 +394,7 @@ pthread::precreate (pthread_attr *newattr)
attr.stacksize = newattr->stacksize;
}
- if (verifyable_object_isvalid (&verifyable_mutex_obj, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject(&verifyable_mutex_obj))
{
thread_printf ("New thread object access mutex is not valid. this %p",
this);
@@ -828,6 +800,17 @@ pthread::getThreadId ()
return thread_id;
}
+/* static members */
+bool
+pthread_attr::isGoodObject (pthread_attr_t const *attr)
+{
+ if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ return false;
+ return true;
+}
+
+/* instance members */
+
pthread_attr::pthread_attr ():verifyable_object (PTHREAD_ATTR_MAGIC),
joinable (PTHREAD_CREATE_JOINABLE), contentionscope (PTHREAD_SCOPE_PROCESS),
inheritsched (PTHREAD_INHERIT_SCHED), stacksize (0)
@@ -898,7 +881,7 @@ pthread_cond::BroadCast ()
if (pthread_mutex_lock (&cond_access))
system_printf ("Failed to lock condition variable access mutex, this %p", this);
int count = waiting;
- if (verifyable_object_isvalid (&mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (&mutex))
{
if (pthread_mutex_unlock (&cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %p", this);
@@ -919,7 +902,7 @@ pthread_cond::Signal ()
{
if (pthread_mutex_lock (&cond_access))
system_printf ("Failed to lock condition variable access mutex, this %p", this);
- if (verifyable_object_isvalid (&mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (&mutex))
{
if (pthread_mutex_unlock (&cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %p",
@@ -1055,6 +1038,14 @@ pthread_key::fixup_after_fork ()
}
}
+bool
+pthread_key::isGoodObject (pthread_key_t const *key)
+{
+ if (verifyable_object_isvalid (key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
+ return false;
+ return true;
+}
+
/* non-static members */
pthread_key::pthread_key (void (*destructor) (void *)):verifyable_object (PTHREAD_KEY_MAGIC)
@@ -1146,6 +1137,23 @@ pthread_key::recreateKeyFromBuffer ()
*Isn't duplicated, it's reopened.
*/
+/* static members */
+bool
+pthread_mutex::isGoodObject (pthread_mutex_t const *thread)
+{
+ if (verifyable_object_isvalid (thread, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ return false;
+ return true;
+}
+
+bool
+pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *thread)
+{
+ if (verifyable_object_isvalid (thread, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER) != VALID_OBJECT)
+ return false;
+ return true;
+}
+
pthread_mutex::pthread_mutex (pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC)
{
/*attr checked in the C call */
@@ -1432,7 +1440,7 @@ pthread::thread_init_wrapper (void *_arg)
}
bool
-pthread::isGoodObject (pthread_t *thread)
+pthread::isGoodObject (pthread_t const *thread)
{
if (verifyable_object_isvalid (thread, PTHREAD_MAGIC) != VALID_OBJECT)
return false;
@@ -1450,7 +1458,7 @@ __pthread_create (pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
DECLARE_TLS_STORAGE;
- if (attr && verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (attr && !pthread_attr::isGoodObject (attr))
return EINVAL;
*thread = new pthread ();
@@ -1622,7 +1630,7 @@ __pthread_attr_init (pthread_attr_t *attr)
if (check_valid_pointer (attr))
return EINVAL;
*attr = new pthread_attr;
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
{
delete (*attr);
*attr = NULL;
@@ -1635,7 +1643,7 @@ int
__pthread_attr_getinheritsched (const pthread_attr_t *attr,
int *inheritsched)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*inheritsched = (*attr)->inheritsched;
return 0;
@@ -1645,7 +1653,7 @@ int
__pthread_attr_getschedparam (const pthread_attr_t *attr,
struct sched_param *param)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*param = (*attr)->schedparam;
return 0;
@@ -1658,7 +1666,7 @@ __pthread_attr_getschedparam (const pthread_attr_t *attr,
int
__pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*policy = SCHED_FIFO;
return 0;
@@ -1668,7 +1676,7 @@ __pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
int
__pthread_attr_getscope (const pthread_attr_t *attr, int *contentionscope)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*contentionscope = (*attr)->contentionscope;
return 0;
@@ -1677,7 +1685,7 @@ __pthread_attr_getscope (const pthread_attr_t *attr, int *contentionscope)
int
__pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
if (detachstate < 0 || detachstate > 1)
return EINVAL;
@@ -1688,7 +1696,7 @@ __pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
int
__pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*detachstate = (*attr)->joinable;
return 0;
@@ -1697,7 +1705,7 @@ __pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
int
__pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
if (inheritsched != PTHREAD_INHERIT_SCHED
&& inheritsched != PTHREAD_EXPLICIT_SCHED)
@@ -1710,7 +1718,7 @@ int
__pthread_attr_setschedparam (pthread_attr_t *attr,
const struct sched_param *param)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
if (!valid_sched_parameters (param))
return ENOTSUP;
@@ -1722,7 +1730,7 @@ __pthread_attr_setschedparam (pthread_attr_t *attr,
int
__pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
if (policy != SCHED_FIFO)
return ENOTSUP;
@@ -1732,7 +1740,7 @@ __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
int
__pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
if (contentionscope != PTHREAD_SCOPE_SYSTEM
&& contentionscope != PTHREAD_SCOPE_PROCESS)
@@ -1748,7 +1756,7 @@ __pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
int
__pthread_attr_setstacksize (pthread_attr_t *attr, size_t size)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
(*attr)->stacksize = size;
return 0;
@@ -1757,7 +1765,7 @@ __pthread_attr_setstacksize (pthread_attr_t *attr, size_t size)
int
__pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
*size = (*attr)->stacksize;
return 0;
@@ -1766,7 +1774,7 @@ __pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size)
int
__pthread_attr_destroy (pthread_attr_t *attr)
{
- if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
+ if (!pthread_attr::isGoodObject (attr))
return EINVAL;
delete (*attr);
*attr = NULL;
@@ -1903,12 +1911,12 @@ __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..
*/
- if (verifyable_object_isvalid (key, PTHREAD_KEY_MAGIC) == VALID_OBJECT)
+ if (pthread_key::isGoodObject (key))
return EBUSY;
*key = new pthread_key (destructor);
- if (verifyable_object_isvalid (key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
+ if (!pthread_key::isGoodObject (key))
{
delete (*key);
*key = NULL;
@@ -1920,7 +1928,7 @@ __pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
int
__pthread_key_delete (pthread_key_t key)
{
- if (verifyable_object_isvalid (&key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
+ if (!pthread_key::isGoodObject (&key))
return EINVAL;
delete (key);
@@ -1961,7 +1969,7 @@ __pthread_setschedparam (pthread_t thread, int policy,
int
__pthread_setspecific (pthread_key_t key, const void *value)
{
- if (verifyable_object_isvalid (&key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
+ if (!pthread_key::isGoodObject (&key))
return EINVAL;
(key)->set (value);
return 0;
@@ -1970,7 +1978,7 @@ __pthread_setspecific (pthread_key_t key, const void *value)
void *
__pthread_getspecific (pthread_key_t key)
{
- if (verifyable_object_isvalid (&key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
+ if (!pthread_key::isGoodObject (&key))
return NULL;
return (key)->get ();
@@ -2058,7 +2066,7 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex,
if (*cond == PTHREAD_COND_INITIALIZER)
__pthread_cond_init (cond, NULL);
- if (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (themutex))
return EINVAL;
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
return EINVAL;
@@ -2233,11 +2241,11 @@ __pthread_mutex_init (pthread_mutex_t *mutex,
if (attr && verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT || check_valid_pointer (mutex))
return EINVAL;
- if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER) == VALID_OBJECT)
+ if (pthread_mutex::isGoodInitializerOrObject (mutex))
return EBUSY;
*mutex = new pthread_mutex (attr ? (*attr) : NULL);
- if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (mutex))
{
delete (*mutex);
*mutex = NULL;
@@ -2253,7 +2261,7 @@ __pthread_mutex_getprioceiling (const pthread_mutex_t *mutex,
pthread_mutex_t *themutex = (pthread_mutex_t *) mutex;
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
__pthread_mutex_init ((pthread_mutex_t *) mutex, NULL);
- if (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (themutex))
return EINVAL;
/*We don't define _POSIX_THREAD_PRIO_PROTECT because we do't currently support
*mutex priorities.
@@ -2296,7 +2304,7 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
pthread_mutex_t *themutex = mutex;
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
__pthread_mutex_init (mutex, NULL);
- if (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (themutex))
return EINVAL;
if ((*themutex)->TryLock ())
return EBUSY;
@@ -2308,7 +2316,7 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
{
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
__pthread_mutex_init (mutex, NULL);
- if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (mutex))
return EINVAL;
(*mutex)->UnLock ();
return 0;
@@ -2319,7 +2327,7 @@ __pthread_mutex_destroy (pthread_mutex_t *mutex)
{
if (check_valid_pointer (mutex) && (*mutex == PTHREAD_MUTEX_INITIALIZER))
return 0;
- if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (mutex))
return EINVAL;
/*reading a word is atomic */
@@ -2338,7 +2346,7 @@ __pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling,
pthread_mutex_t *themutex = mutex;
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
__pthread_mutex_init (mutex, NULL);
- if (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
+ if (!pthread_mutex::isGoodObject (themutex))
return EINVAL;
return ENOSYS;
}
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index 23fe01f..9238153 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -176,6 +176,7 @@ verifyable_object_state verifyable_object_isvalid (void const *, long, void *);
class pthread_key:public verifyable_object
{
public:
+ static bool isGoodObject (pthread_key_t const *);
DWORD dwTlsIndex;
void *fork_buf;
@@ -228,6 +229,7 @@ private:
class pthread_attr:public verifyable_object
{
public:
+ static bool isGoodObject(pthread_attr_t const *);
int joinable;
int contentionscope;
int inheritsched;
@@ -241,6 +243,7 @@ public:
class pthread_mutexattr:public verifyable_object
{
public:
+ static bool isGoodObject(pthread_mutexattr_t const *);
int pshared;
int mutextype;
pthread_mutexattr ();
@@ -250,6 +253,8 @@ public:
class pthread_mutex:public verifyable_object
{
public:
+ static bool isGoodObject(pthread_mutex_t const *);
+ static bool isGoodInitializerOrObject(pthread_mutex_t const *);
CRITICAL_SECTION criticalsection;
HANDLE win32_obj_id;
LONG condwaits;
@@ -290,7 +295,7 @@ public:
virtual ~pthread ();
static void initMainThread(pthread *, HANDLE);
- static bool isGoodObject(pthread_t *);
+ static bool isGoodObject(pthread_t const *);
static void atforkprepare();
static void atforkparent();
static void atforkchild();
@@ -356,6 +361,7 @@ class pthreadNull : public pthread
class pthread_condattr:public verifyable_object
{
public:
+ static bool isGoodObject(pthread_condattr_t *);
int shared;
pthread_condattr ();
@@ -365,6 +371,7 @@ public:
class pthread_cond:public verifyable_object
{
public:
+ static bool isGoodObject(pthread_cond_t *);
int shared;
LONG waiting;
LONG ExitingWait;
@@ -393,6 +400,7 @@ public:
class semaphore:public verifyable_object
{
public:
+ static bool isGoodObject(semaphore **);
HANDLE win32_obj_id;
class semaphore * next;
int shared;