2002-09-21 Robert Collins <rbtcollins@hotmail.com>
* thread.cc: Change verifyable_object_isvalid calls with PTHREAD_CONDATTR_MAGIC, PTHREAD_MUTEXATTR_MAGIC, PTHREAD_COND_MAGIC, SEM_MAGIC to objecttype::isGoodObject() calls throughout. (pthread_condattr::isGoodObject): Implement. (pthread_mutex::isGoodInitializer): Implement. (pthread_mutex::isGoodInitializerOrObject): Minor bugfix in the check for verifyable_object_isvalid result. (pthread_mutexattr::isGoodObject): Implement. (pthread_cond::isGoodObject): Ditto. (pthread_cond::isGoodInitializer): Ditto. (pthread_cond::isGoodInitializerOrObject): Ditto. (semaphore::isGoodObject): Ditto. * thread.h (pthread_mutex::isGoodInitializer): Declare. (pthread_condattr::isGoodObject): Ditto. (pthread_cond::isGoodObject): Const correctness. (pthread_cond::isGoodInitializer): Declare. (pthread_cond::isGoodInitializerOrObject): Ditto. (semaphore::isGoodObject): Const correctness.
This commit is contained in:
parent
4e2822f160
commit
8b1978c30c
@ -1,3 +1,24 @@
|
|||||||
|
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
|
||||||
|
|
||||||
|
* thread.cc: Change verifyable_object_isvalid calls with
|
||||||
|
PTHREAD_CONDATTR_MAGIC, PTHREAD_MUTEXATTR_MAGIC, PTHREAD_COND_MAGIC,
|
||||||
|
SEM_MAGIC to objecttype::isGoodObject() calls throughout.
|
||||||
|
(pthread_condattr::isGoodObject): Implement.
|
||||||
|
(pthread_mutex::isGoodInitializer): Implement.
|
||||||
|
(pthread_mutex::isGoodInitializerOrObject): Minor bugfix in the
|
||||||
|
check for verifyable_object_isvalid result.
|
||||||
|
(pthread_mutexattr::isGoodObject): Implement.
|
||||||
|
(pthread_cond::isGoodObject): Ditto.
|
||||||
|
(pthread_cond::isGoodInitializer): Ditto.
|
||||||
|
(pthread_cond::isGoodInitializerOrObject): Ditto.
|
||||||
|
(semaphore::isGoodObject): Ditto.
|
||||||
|
* thread.h (pthread_mutex::isGoodInitializer): Declare.
|
||||||
|
(pthread_condattr::isGoodObject): Ditto.
|
||||||
|
(pthread_cond::isGoodObject): Const correctness.
|
||||||
|
(pthread_cond::isGoodInitializer): Declare.
|
||||||
|
(pthread_cond::isGoodInitializerOrObject): Ditto.
|
||||||
|
(semaphore::isGoodObject): Const correctness.
|
||||||
|
|
||||||
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
|
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
|
||||||
|
|
||||||
* thread.cc: Change verifyable_object_isvalid calls with
|
* thread.cc: Change verifyable_object_isvalid calls with
|
||||||
|
@ -822,6 +822,14 @@ pthread_attr::~pthread_attr ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_condattr::isGoodObject (pthread_condattr_t const *attr)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (attr, PTHREAD_CONDATTR_MAGIC) != VALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_condattr::pthread_condattr ():verifyable_object
|
pthread_condattr::pthread_condattr ():verifyable_object
|
||||||
(PTHREAD_CONDATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE)
|
(PTHREAD_CONDATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE)
|
||||||
{
|
{
|
||||||
@ -1139,17 +1147,25 @@ pthread_key::recreateKeyFromBuffer ()
|
|||||||
|
|
||||||
/* static members */
|
/* static members */
|
||||||
bool
|
bool
|
||||||
pthread_mutex::isGoodObject (pthread_mutex_t const *thread)
|
pthread_mutex::isGoodObject (pthread_mutex_t const *mutex)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (thread, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *thread)
|
pthread_mutex::isGoodInitializer (pthread_mutex_t const *mutex)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (thread, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER) != VALID_OBJECT)
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER) != VALID_STATIC_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *mutex)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER) == INVALID_OBJECT)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1257,6 +1273,14 @@ pthread_mutex::fixup_after_fork ()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_mutexattr::isGoodObject (pthread_mutexattr_t const * attr)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutexattr::pthread_mutexattr ():verifyable_object (PTHREAD_MUTEXATTR_MAGIC),
|
pthread_mutexattr::pthread_mutexattr ():verifyable_object (PTHREAD_MUTEXATTR_MAGIC),
|
||||||
pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_DEFAULT)
|
pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_DEFAULT)
|
||||||
{
|
{
|
||||||
@ -1986,13 +2010,36 @@ __pthread_getspecific (pthread_key_t key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*Thread synchronisation */
|
/*Thread synchronisation */
|
||||||
|
bool
|
||||||
|
pthread_cond::isGoodObject (pthread_cond_t const *cond)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_cond::isGoodInitializer (pthread_cond_t const *cond)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER) != VALID_STATIC_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_cond::isGoodInitializerOrObject (pthread_cond_t const *cond)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER) == INVALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__pthread_cond_destroy (pthread_cond_t *cond)
|
__pthread_cond_destroy (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
if (check_valid_pointer (cond) && (*cond == PTHREAD_COND_INITIALIZER))
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
return 0;
|
return 0;
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
/*reads are atomic */
|
/*reads are atomic */
|
||||||
@ -2008,15 +2055,15 @@ __pthread_cond_destroy (pthread_cond_t *cond)
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (attr && !pthread_condattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER) == VALID_OBJECT)
|
if (pthread_cond::isGoodObject (cond))
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
*cond = new pthread_cond (attr ? (*attr) : NULL);
|
*cond = new pthread_cond (attr ? (*attr) : NULL);
|
||||||
|
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
{
|
{
|
||||||
delete (*cond);
|
delete (*cond);
|
||||||
*cond = NULL;
|
*cond = NULL;
|
||||||
@ -2029,9 +2076,9 @@ __pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr)
|
|||||||
int
|
int
|
||||||
__pthread_cond_broadcast (pthread_cond_t *cond)
|
__pthread_cond_broadcast (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
if (*cond == PTHREAD_COND_INITIALIZER)
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
__pthread_cond_init (cond, NULL);
|
__pthread_cond_init (cond, NULL);
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
(*cond)->BroadCast ();
|
(*cond)->BroadCast ();
|
||||||
@ -2042,9 +2089,9 @@ __pthread_cond_broadcast (pthread_cond_t *cond)
|
|||||||
int
|
int
|
||||||
__pthread_cond_signal (pthread_cond_t *cond)
|
__pthread_cond_signal (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
if (*cond == PTHREAD_COND_INITIALIZER)
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
__pthread_cond_init (cond, NULL);
|
__pthread_cond_init (cond, NULL);
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
(*cond)->Signal ();
|
(*cond)->Signal ();
|
||||||
@ -2063,12 +2110,12 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
||||||
__pthread_mutex_init (mutex, NULL);
|
__pthread_mutex_init (mutex, NULL);
|
||||||
themutex = mutex;
|
themutex = mutex;
|
||||||
if (*cond == PTHREAD_COND_INITIALIZER)
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
__pthread_cond_init (cond, NULL);
|
__pthread_cond_init (cond, NULL);
|
||||||
|
|
||||||
if (!pthread_mutex::isGoodObject (themutex))
|
if (!pthread_mutex::isGoodObject (themutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
/*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**/
|
||||||
@ -2135,8 +2182,9 @@ pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
|
|||||||
int
|
int
|
||||||
__pthread_condattr_init (pthread_condattr_t *condattr)
|
__pthread_condattr_init (pthread_condattr_t *condattr)
|
||||||
{
|
{
|
||||||
|
/* FIXME: we dereference blindly! */
|
||||||
*condattr = new pthread_condattr;
|
*condattr = new pthread_condattr;
|
||||||
if (verifyable_object_isvalid (condattr, PTHREAD_CONDATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_condattr::isGoodObject (condattr))
|
||||||
{
|
{
|
||||||
delete (*condattr);
|
delete (*condattr);
|
||||||
*condattr = NULL;
|
*condattr = NULL;
|
||||||
@ -2148,7 +2196,7 @@ __pthread_condattr_init (pthread_condattr_t *condattr)
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (!pthread_condattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
*pshared = (*attr)->shared;
|
*pshared = (*attr)->shared;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2157,7 +2205,7 @@ __pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared)
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (!pthread_condattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if ((pshared < 0) || (pshared > 1))
|
if ((pshared < 0) || (pshared > 1))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2171,7 +2219,7 @@ __pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared)
|
|||||||
int
|
int
|
||||||
__pthread_condattr_destroy (pthread_condattr_t *condattr)
|
__pthread_condattr_destroy (pthread_condattr_t *condattr)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (condattr, PTHREAD_CONDATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_condattr::isGoodObject (condattr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
delete (*condattr);
|
delete (*condattr);
|
||||||
*condattr = NULL;
|
*condattr = NULL;
|
||||||
@ -2238,10 +2286,11 @@ int
|
|||||||
__pthread_mutex_init (pthread_mutex_t *mutex,
|
__pthread_mutex_init (pthread_mutex_t *mutex,
|
||||||
const pthread_mutexattr_t *attr)
|
const pthread_mutexattr_t *attr)
|
||||||
{
|
{
|
||||||
if (attr && verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT || check_valid_pointer (mutex))
|
if (attr && !pthread_mutexattr::isGoodObject (attr) || check_valid_pointer (mutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
if (pthread_mutex::isGoodInitializerOrObject (mutex))
|
/* FIXME: bugfix: we should check *mutex being a valid address */
|
||||||
|
if (pthread_mutex::isGoodObject (mutex))
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
*mutex = new pthread_mutex (attr ? (*attr) : NULL);
|
*mutex = new pthread_mutex (attr ? (*attr) : NULL);
|
||||||
@ -2259,7 +2308,7 @@ __pthread_mutex_getprioceiling (const pthread_mutex_t *mutex,
|
|||||||
int *prioceiling)
|
int *prioceiling)
|
||||||
{
|
{
|
||||||
pthread_mutex_t *themutex = (pthread_mutex_t *) mutex;
|
pthread_mutex_t *themutex = (pthread_mutex_t *) mutex;
|
||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
__pthread_mutex_init ((pthread_mutex_t *) mutex, NULL);
|
__pthread_mutex_init ((pthread_mutex_t *) mutex, NULL);
|
||||||
if (!pthread_mutex::isGoodObject (themutex))
|
if (!pthread_mutex::isGoodObject (themutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2278,13 +2327,17 @@ int
|
|||||||
__pthread_mutex_lock (pthread_mutex_t *mutex)
|
__pthread_mutex_lock (pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_t *themutex = mutex;
|
pthread_mutex_t *themutex = mutex;
|
||||||
|
/* This could be simplified via isGoodInitializerOrObject
|
||||||
|
and isGoodInitializer, but in a performance critical call like this....
|
||||||
|
no.
|
||||||
|
*/
|
||||||
switch (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER))
|
switch (verifyable_object_isvalid (themutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER))
|
||||||
{
|
{
|
||||||
case INVALID_OBJECT:
|
case INVALID_OBJECT:
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
break;
|
break;
|
||||||
case VALID_STATIC_OBJECT:
|
case VALID_STATIC_OBJECT:
|
||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
{
|
{
|
||||||
int rv = __pthread_mutex_init (mutex, NULL);
|
int rv = __pthread_mutex_init (mutex, NULL);
|
||||||
if (rv)
|
if (rv)
|
||||||
@ -2302,7 +2355,7 @@ int
|
|||||||
__pthread_mutex_trylock (pthread_mutex_t *mutex)
|
__pthread_mutex_trylock (pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_t *themutex = mutex;
|
pthread_mutex_t *themutex = mutex;
|
||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
__pthread_mutex_init (mutex, NULL);
|
__pthread_mutex_init (mutex, NULL);
|
||||||
if (!pthread_mutex::isGoodObject (themutex))
|
if (!pthread_mutex::isGoodObject (themutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2314,7 +2367,7 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
|
|||||||
int
|
int
|
||||||
__pthread_mutex_unlock (pthread_mutex_t *mutex)
|
__pthread_mutex_unlock (pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
__pthread_mutex_init (mutex, NULL);
|
__pthread_mutex_init (mutex, NULL);
|
||||||
if (!pthread_mutex::isGoodObject (mutex))
|
if (!pthread_mutex::isGoodObject (mutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2325,7 +2378,7 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
|
|||||||
int
|
int
|
||||||
__pthread_mutex_destroy (pthread_mutex_t *mutex)
|
__pthread_mutex_destroy (pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
if (check_valid_pointer (mutex) && (*mutex == PTHREAD_MUTEX_INITIALIZER))
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
return 0;
|
return 0;
|
||||||
if (!pthread_mutex::isGoodObject (mutex))
|
if (!pthread_mutex::isGoodObject (mutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2344,7 +2397,7 @@ __pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling,
|
|||||||
int *old_ceiling)
|
int *old_ceiling)
|
||||||
{
|
{
|
||||||
pthread_mutex_t *themutex = mutex;
|
pthread_mutex_t *themutex = mutex;
|
||||||
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
|
if (pthread_mutex::isGoodInitializer (mutex))
|
||||||
__pthread_mutex_init (mutex, NULL);
|
__pthread_mutex_init (mutex, NULL);
|
||||||
if (!pthread_mutex::isGoodObject (themutex))
|
if (!pthread_mutex::isGoodObject (themutex))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2357,7 +2410,7 @@ int
|
|||||||
__pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr,
|
__pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr,
|
||||||
int *protocol)
|
int *protocol)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return ENOSYS;
|
return ENOSYS;
|
||||||
}
|
}
|
||||||
@ -2366,7 +2419,7 @@ int
|
|||||||
__pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
|
__pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
|
||||||
int *pshared)
|
int *pshared)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
*pshared = (*attr)->pshared;
|
*pshared = (*attr)->pshared;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2379,7 +2432,7 @@ __pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
|
|||||||
int
|
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_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
*type = (*attr)->mutextype;
|
*type = (*attr)->mutextype;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2393,11 +2446,11 @@ __pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
|
|||||||
int
|
int
|
||||||
__pthread_mutexattr_init (pthread_mutexattr_t *attr)
|
__pthread_mutexattr_init (pthread_mutexattr_t *attr)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != INVALID_OBJECT)
|
if (pthread_mutexattr::isGoodObject (attr))
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
*attr = new pthread_mutexattr ();
|
*attr = new pthread_mutexattr ();
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
{
|
{
|
||||||
delete (*attr);
|
delete (*attr);
|
||||||
*attr = NULL;
|
*attr = NULL;
|
||||||
@ -2409,7 +2462,7 @@ __pthread_mutexattr_init (pthread_mutexattr_t *attr)
|
|||||||
int
|
int
|
||||||
__pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
|
__pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
delete (*attr);
|
delete (*attr);
|
||||||
*attr = NULL;
|
*attr = NULL;
|
||||||
@ -2421,7 +2474,7 @@ __pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return ENOSYS;
|
return ENOSYS;
|
||||||
}
|
}
|
||||||
@ -2431,7 +2484,7 @@ int
|
|||||||
__pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr,
|
__pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr,
|
||||||
int prioceiling)
|
int prioceiling)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return ENOSYS;
|
return ENOSYS;
|
||||||
}
|
}
|
||||||
@ -2440,7 +2493,7 @@ int
|
|||||||
__pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
|
__pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
|
||||||
int *prioceiling)
|
int *prioceiling)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return ENOSYS;
|
return ENOSYS;
|
||||||
}
|
}
|
||||||
@ -2448,7 +2501,7 @@ __pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
/*we don't use pshared for anything as yet. We need to test PROCESS_SHARED
|
/*we don't use pshared for anything as yet. We need to test PROCESS_SHARED
|
||||||
*functionality
|
*functionality
|
||||||
@ -2463,7 +2516,7 @@ __pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared)
|
|||||||
int
|
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) != VALID_OBJECT)
|
if (!pthread_mutexattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (type != PTHREAD_MUTEX_RECURSIVE)
|
if (type != PTHREAD_MUTEX_RECURSIVE)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -2472,11 +2525,21 @@ __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*Semaphores */
|
/*Semaphores */
|
||||||
|
|
||||||
|
/* static members */
|
||||||
|
bool
|
||||||
|
semaphore::isGoodObject (sem_t const * sem)
|
||||||
|
{
|
||||||
|
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
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) != INVALID_OBJECT)
|
if (semaphore::isGoodObject (sem))
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
if (value > SEM_VALUE_MAX)
|
if (value > SEM_VALUE_MAX)
|
||||||
@ -2484,7 +2547,7 @@ __sem_init (sem_t *sem, int pshared, unsigned int value)
|
|||||||
|
|
||||||
*sem = new semaphore (pshared, value);
|
*sem = new semaphore (pshared, value);
|
||||||
|
|
||||||
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
if (!semaphore::isGoodObject (sem))
|
||||||
{
|
{
|
||||||
delete (*sem);
|
delete (*sem);
|
||||||
*sem = NULL;
|
*sem = NULL;
|
||||||
@ -2496,7 +2559,7 @@ __sem_init (sem_t *sem, int pshared, unsigned int value)
|
|||||||
int
|
int
|
||||||
__sem_destroy (sem_t *sem)
|
__sem_destroy (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
if (!semaphore::isGoodObject (sem))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
/*FIXME - new feature - test for busy against threads... */
|
/*FIXME - new feature - test for busy against threads... */
|
||||||
@ -2509,7 +2572,7 @@ __sem_destroy (sem_t *sem)
|
|||||||
int
|
int
|
||||||
__sem_wait (sem_t *sem)
|
__sem_wait (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
if (!semaphore::isGoodObject (sem))
|
||||||
{
|
{
|
||||||
set_errno (EINVAL);
|
set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2522,7 +2585,7 @@ __sem_wait (sem_t *sem)
|
|||||||
int
|
int
|
||||||
__sem_trywait (sem_t *sem)
|
__sem_trywait (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
if (!semaphore::isGoodObject (sem))
|
||||||
{
|
{
|
||||||
set_errno (EINVAL);
|
set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2534,7 +2597,7 @@ __sem_trywait (sem_t *sem)
|
|||||||
int
|
int
|
||||||
__sem_post (sem_t *sem)
|
__sem_post (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
if (!semaphore::isGoodObject (sem))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
(*sem)->Post ();
|
(*sem)->Post ();
|
||||||
|
@ -254,6 +254,7 @@ class pthread_mutex:public verifyable_object
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool isGoodObject(pthread_mutex_t const *);
|
static bool isGoodObject(pthread_mutex_t const *);
|
||||||
|
static bool isGoodInitializer(pthread_mutex_t const *);
|
||||||
static bool isGoodInitializerOrObject(pthread_mutex_t const *);
|
static bool isGoodInitializerOrObject(pthread_mutex_t const *);
|
||||||
CRITICAL_SECTION criticalsection;
|
CRITICAL_SECTION criticalsection;
|
||||||
HANDLE win32_obj_id;
|
HANDLE win32_obj_id;
|
||||||
@ -361,7 +362,7 @@ class pthreadNull : public pthread
|
|||||||
class pthread_condattr:public verifyable_object
|
class pthread_condattr:public verifyable_object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool isGoodObject(pthread_condattr_t *);
|
static bool isGoodObject(pthread_condattr_t const *);
|
||||||
int shared;
|
int shared;
|
||||||
|
|
||||||
pthread_condattr ();
|
pthread_condattr ();
|
||||||
@ -371,7 +372,9 @@ public:
|
|||||||
class pthread_cond:public verifyable_object
|
class pthread_cond:public verifyable_object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool isGoodObject(pthread_cond_t *);
|
static bool isGoodObject(pthread_cond_t const *);
|
||||||
|
static bool isGoodInitializer(pthread_cond_t const *);
|
||||||
|
static bool isGoodInitializerOrObject(pthread_cond_t const *);
|
||||||
int shared;
|
int shared;
|
||||||
LONG waiting;
|
LONG waiting;
|
||||||
LONG ExitingWait;
|
LONG ExitingWait;
|
||||||
@ -400,7 +403,7 @@ public:
|
|||||||
class semaphore:public verifyable_object
|
class semaphore:public verifyable_object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool isGoodObject(semaphore **);
|
static bool isGoodObject(sem_t const *);
|
||||||
HANDLE win32_obj_id;
|
HANDLE win32_obj_id;
|
||||||
class semaphore * next;
|
class semaphore * next;
|
||||||
int shared;
|
int shared;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user