Applied cond_init patch
This commit is contained in:
parent
93353aee63
commit
ed9fe4559c
@ -1,3 +1,20 @@
|
|||||||
|
2003-01-09 Thomas Pfaff <tpfaff@gmx.net>
|
||||||
|
|
||||||
|
* pthread.cc (pthread_cond_init): Use new pthread_cond::init.
|
||||||
|
* thread.cc: Some white spaces cleanups.
|
||||||
|
Change __pthread_cond_init to pthread_cond::init throughout.
|
||||||
|
(nativeMutex): Move class methods outside pthread_mutex.
|
||||||
|
(MTinterface::Init): Initialize pthread_cond init lock.
|
||||||
|
(pthread_cond::condInitializationLock): Instantiate.
|
||||||
|
(pthread_cond::initMutex): New Method.
|
||||||
|
(pthread_cond::isGoodInitializerOrBadObject): Ditto.
|
||||||
|
* thread.h: Some white spaces cleanups.
|
||||||
|
(nativeMutex): Move class declaration outside pthread_mutex.
|
||||||
|
(pthread_cond::condInitializationLock): New static member.
|
||||||
|
(pthread_cond::initMutex): New Method.
|
||||||
|
(pthread_cond::isGoodInitializerOrBadObject): Ditto.
|
||||||
|
(__pthread_cond_init): Remove prototype.
|
||||||
|
|
||||||
2003-01-09 Corinna Vinschen <corinna@vinschen.de>
|
2003-01-09 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_disk_file.cc (num_entries): Return 2 as link count if
|
* fhandler_disk_file.cc (num_entries): Return 2 as link count if
|
||||||
|
@ -349,7 +349,7 @@ 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)
|
||||||
{
|
{
|
||||||
return __pthread_cond_init (cond, attr);
|
return pthread_cond::init (cond, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -72,6 +72,37 @@ _reent_winsup ()
|
|||||||
return _r->_winsup;
|
return _r->_winsup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nativeMutex::init ()
|
||||||
|
{
|
||||||
|
theHandle = CreateMutex (&sec_none_nih, FALSE, NULL);
|
||||||
|
if (!theHandle)
|
||||||
|
{
|
||||||
|
debug_printf ("CreateMutex failed. %E");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nativeMutex::lock ()
|
||||||
|
{
|
||||||
|
DWORD waitResult = WaitForSingleObject (theHandle, INFINITE);
|
||||||
|
if (waitResult != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
system_printf ("Received unexpected wait result %d on handle %p, %E", waitResult, theHandle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nativeMutex::unlock ()
|
||||||
|
{
|
||||||
|
if (!ReleaseMutex (theHandle))
|
||||||
|
system_printf ("Received a unexpected result releasing mutex. %E");
|
||||||
|
}
|
||||||
|
|
||||||
inline LPCRITICAL_SECTION
|
inline LPCRITICAL_SECTION
|
||||||
ResourceLocks::Lock (int _resid)
|
ResourceLocks::Lock (int _resid)
|
||||||
{
|
{
|
||||||
@ -168,6 +199,7 @@ MTinterface::Init (int forked)
|
|||||||
reent_key.set (&reents);
|
reent_key.set (&reents);
|
||||||
|
|
||||||
pthread_mutex::initMutex ();
|
pthread_mutex::initMutex ();
|
||||||
|
pthread_cond::initMutex ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -743,6 +775,19 @@ pthread_condattr::~pthread_condattr ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is used for cond creation protection within a single process only */
|
||||||
|
nativeMutex NO_COPY pthread_cond::condInitializationLock;
|
||||||
|
|
||||||
|
/* We can only be called once.
|
||||||
|
TODO: (no rush) use a non copied memory section to
|
||||||
|
hold an initialization flag. */
|
||||||
|
void
|
||||||
|
pthread_cond::initMutex ()
|
||||||
|
{
|
||||||
|
if (!condInitializationLock.init ())
|
||||||
|
api_fatal ("Could not create win32 Mutex for pthread cond static initializer support.");
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
int temperr;
|
||||||
@ -1090,14 +1135,14 @@ pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *mutex)
|
|||||||
bool
|
bool
|
||||||
pthread_mutex::isGoodInitializerOrBadObject (pthread_mutex_t const *mutex)
|
pthread_mutex::isGoodInitializerOrBadObject (pthread_mutex_t const *mutex)
|
||||||
{
|
{
|
||||||
verifyable_object_state objectState = verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER);
|
verifyable_object_state objectState = verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER);
|
||||||
if (objectState == VALID_OBJECT)
|
if (objectState == VALID_OBJECT)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is used for mutex creation protection within a single process only */
|
/* This is used for mutex creation protection within a single process only */
|
||||||
pthread_mutex::nativeMutex pthread_mutex::mutexInitializationLock NO_COPY;
|
nativeMutex NO_COPY pthread_mutex::mutexInitializationLock;
|
||||||
|
|
||||||
/* We can only be called once.
|
/* We can only be called once.
|
||||||
TODO: (no rush) use a non copied memory section to
|
TODO: (no rush) use a non copied memory section to
|
||||||
@ -1212,37 +1257,6 @@ pthread_mutex::fixup_after_fork ()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
pthread_mutex::nativeMutex::init ()
|
|
||||||
{
|
|
||||||
theHandle = CreateMutex (&sec_none_nih, FALSE, NULL);
|
|
||||||
if (!theHandle)
|
|
||||||
{
|
|
||||||
debug_printf ("CreateMutex failed. %E");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
pthread_mutex::nativeMutex::lock ()
|
|
||||||
{
|
|
||||||
DWORD waitResult = WaitForSingleObject (theHandle, INFINITE);
|
|
||||||
if (waitResult != WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
system_printf ("Received unexpected wait result %d on handle %p, %E", waitResult, theHandle);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
pthread_mutex::nativeMutex::unlock ()
|
|
||||||
{
|
|
||||||
if (!ReleaseMutex (theHandle))
|
|
||||||
system_printf ("Received a unexpected result releasing mutex. %E");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pthread_mutexattr::isGoodObject (pthread_mutexattr_t const * attr)
|
pthread_mutexattr::isGoodObject (pthread_mutexattr_t const * attr)
|
||||||
{
|
{
|
||||||
@ -2001,6 +2015,15 @@ pthread_cond::isGoodInitializerOrObject (pthread_cond_t const *cond)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pthread_cond::isGoodInitializerOrBadObject (pthread_cond_t const *cond)
|
||||||
|
{
|
||||||
|
verifyable_object_state objectState = verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER);
|
||||||
|
if (objectState == VALID_OBJECT)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__pthread_cond_destroy (pthread_cond_t *cond)
|
__pthread_cond_destroy (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
@ -2020,23 +2043,28 @@ __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 && !pthread_condattr::isGoodObject (attr))
|
if (attr && !pthread_condattr::isGoodObject (attr))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
if (!condInitializationLock.lock ())
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
if (pthread_cond::isGoodObject (cond))
|
if (!isGoodInitializerOrBadObject (cond))
|
||||||
return EBUSY;
|
{
|
||||||
|
condInitializationLock.unlock ();
|
||||||
|
return EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
*cond = new pthread_cond (attr ? (*attr) : NULL);
|
*cond = new pthread_cond (attr ? (*attr) : NULL);
|
||||||
|
if (!isGoodObject (cond))
|
||||||
if (!pthread_cond::isGoodObject (cond))
|
|
||||||
{
|
{
|
||||||
delete (*cond);
|
delete (*cond);
|
||||||
*cond = NULL;
|
*cond = NULL;
|
||||||
|
condInitializationLock.unlock ();
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
}
|
}
|
||||||
|
condInitializationLock.unlock ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2044,7 +2072,7 @@ int
|
|||||||
__pthread_cond_broadcast (pthread_cond_t *cond)
|
__pthread_cond_broadcast (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
if (pthread_cond::isGoodInitializer (cond))
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
__pthread_cond_init (cond, NULL);
|
pthread_cond::init (cond, NULL);
|
||||||
if (!pthread_cond::isGoodObject (cond))
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
@ -2057,7 +2085,7 @@ int
|
|||||||
__pthread_cond_signal (pthread_cond_t *cond)
|
__pthread_cond_signal (pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
if (pthread_cond::isGoodInitializer (cond))
|
if (pthread_cond::isGoodInitializer (cond))
|
||||||
__pthread_cond_init (cond, NULL);
|
pthread_cond::init (cond, NULL);
|
||||||
if (!pthread_cond::isGoodObject (cond))
|
if (!pthread_cond::isGoodObject (cond))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
@ -2078,7 +2106,7 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|||||||
pthread_mutex::init (mutex, NULL);
|
pthread_mutex::init (mutex, NULL);
|
||||||
themutex = mutex;
|
themutex = mutex;
|
||||||
if (pthread_cond::isGoodInitializer (cond))
|
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;
|
||||||
|
@ -121,6 +121,16 @@ void AssertResourceOwner (int, int);
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class nativeMutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool init ();
|
||||||
|
bool lock ();
|
||||||
|
void unlock ();
|
||||||
|
private:
|
||||||
|
HANDLE theHandle;
|
||||||
|
};
|
||||||
|
|
||||||
class per_process;
|
class per_process;
|
||||||
class pinfo;
|
class pinfo;
|
||||||
|
|
||||||
@ -288,9 +298,9 @@ public:
|
|||||||
class pthread_mutex:public verifyable_object
|
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 isGoodInitializer (pthread_mutex_t const *);
|
||||||
static bool isGoodInitializerOrObject(pthread_mutex_t const *);
|
static bool isGoodInitializerOrObject (pthread_mutex_t const *);
|
||||||
static bool isGoodInitializerOrBadObject (pthread_mutex_t const *mutex);
|
static bool isGoodInitializerOrBadObject (pthread_mutex_t const *mutex);
|
||||||
static void initMutex ();
|
static void initMutex ();
|
||||||
static int init (pthread_mutex_t *, const pthread_mutexattr_t *);
|
static int init (pthread_mutex_t *, const pthread_mutexattr_t *);
|
||||||
@ -309,15 +319,8 @@ public:
|
|||||||
pthread_mutex (pthread_mutexattr * = NULL);
|
pthread_mutex (pthread_mutexattr * = NULL);
|
||||||
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
||||||
~pthread_mutex ();
|
~pthread_mutex ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class nativeMutex {
|
|
||||||
public:
|
|
||||||
bool init();
|
|
||||||
bool lock();
|
|
||||||
void unlock();
|
|
||||||
private:
|
|
||||||
HANDLE theHandle;
|
|
||||||
};
|
|
||||||
static nativeMutex mutexInitializationLock;
|
static nativeMutex mutexInitializationLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -432,9 +435,13 @@ public:
|
|||||||
class pthread_cond:public verifyable_object
|
class pthread_cond:public verifyable_object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool isGoodObject(pthread_cond_t const *);
|
static bool isGoodObject (pthread_cond_t const *);
|
||||||
static bool isGoodInitializer(pthread_cond_t const *);
|
static bool isGoodInitializer (pthread_cond_t const *);
|
||||||
static bool isGoodInitializerOrObject(pthread_cond_t const *);
|
static bool isGoodInitializerOrObject (pthread_cond_t const *);
|
||||||
|
static bool isGoodInitializerOrBadObject (pthread_cond_t const *);
|
||||||
|
static void initMutex ();
|
||||||
|
static int init (pthread_cond_t *, const pthread_condattr_t *);
|
||||||
|
|
||||||
int shared;
|
int shared;
|
||||||
LONG waiting;
|
LONG waiting;
|
||||||
LONG ExitingWait;
|
LONG ExitingWait;
|
||||||
@ -450,6 +457,9 @@ public:
|
|||||||
|
|
||||||
pthread_cond (pthread_condattr *);
|
pthread_cond (pthread_condattr *);
|
||||||
~pthread_cond ();
|
~pthread_cond ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static nativeMutex condInitializationLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
class pthread_once
|
class pthread_once
|
||||||
@ -559,8 +569,6 @@ void *__pthread_getspecific (pthread_key_t key);
|
|||||||
|
|
||||||
/* Thead synchroniation */
|
/* Thead synchroniation */
|
||||||
int __pthread_cond_destroy (pthread_cond_t * cond);
|
int __pthread_cond_destroy (pthread_cond_t * cond);
|
||||||
int __pthread_cond_init (pthread_cond_t * cond,
|
|
||||||
const pthread_condattr_t * attr);
|
|
||||||
int __pthread_cond_signal (pthread_cond_t * cond);
|
int __pthread_cond_signal (pthread_cond_t * cond);
|
||||||
int __pthread_cond_broadcast (pthread_cond_t * cond);
|
int __pthread_cond_broadcast (pthread_cond_t * cond);
|
||||||
int __pthread_condattr_init (pthread_condattr_t * condattr);
|
int __pthread_condattr_init (pthread_condattr_t * condattr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user