aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Pfaff <tpfaff@gmx.net>2003-01-09 20:40:44 +0000
committerThomas Pfaff <tpfaff@gmx.net>2003-01-09 20:40:44 +0000
commited9fe4559ca16bd11a3ab7144951b97b9378608b (patch)
tree94c1de8b337c5fa564d4298395c512561b26f279
parent93353aee63945ba333407a21f7d5c69eea58265f (diff)
downloadnewlib-ed9fe4559ca16bd11a3ab7144951b97b9378608b.zip
newlib-ed9fe4559ca16bd11a3ab7144951b97b9378608b.tar.gz
newlib-ed9fe4559ca16bd11a3ab7144951b97b9378608b.tar.bz2
Applied cond_init patch
-rw-r--r--winsup/cygwin/ChangeLog17
-rw-r--r--winsup/cygwin/pthread.cc2
-rw-r--r--winsup/cygwin/thread.cc116
-rw-r--r--winsup/cygwin/thread.h40
4 files changed, 114 insertions, 61 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index a42aeb4..62e17f1 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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>
* fhandler_disk_file.cc (num_entries): Return 2 as link count if
diff --git a/winsup/cygwin/pthread.cc b/winsup/cygwin/pthread.cc
index 30d0480..09a494d 100644
--- a/winsup/cygwin/pthread.cc
+++ b/winsup/cygwin/pthread.cc
@@ -349,7 +349,7 @@ pthread_cond_destroy (pthread_cond_t * cond)
int
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
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index b77a2e5..119039a 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -72,6 +72,37 @@ _reent_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
ResourceLocks::Lock (int _resid)
{
@@ -168,6 +199,7 @@ MTinterface::Init (int forked)
reent_key.set (&reents);
pthread_mutex::initMutex ();
+ pthread_cond::initMutex ();
}
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)
{
int temperr;
@@ -1090,14 +1135,14 @@ pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *mutex)
bool
pthread_mutex::isGoodInitializerOrBadObject (pthread_mutex_t const *mutex)
{
- verifyable_object_state objectState = verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER);
- if (objectState == VALID_OBJECT)
+ verifyable_object_state objectState = verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC, PTHREAD_MUTEX_INITIALIZER);
+ if (objectState == VALID_OBJECT)
return false;
- return true;
+ return true;
}
/* 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.
TODO: (no rush) use a non copied memory section to
@@ -1213,37 +1258,6 @@ pthread_mutex::fixup_after_fork ()
}
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
pthread_mutexattr::isGoodObject (pthread_mutexattr_t const * attr)
{
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
@@ -2001,6 +2015,15 @@ pthread_cond::isGoodInitializerOrObject (pthread_cond_t const *cond)
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
__pthread_cond_destroy (pthread_cond_t *cond)
{
@@ -2020,23 +2043,28 @@ __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 && !pthread_condattr::isGoodObject (attr))
return EINVAL;
+ if (!condInitializationLock.lock ())
+ return EINVAL;
- if (pthread_cond::isGoodObject (cond))
- return EBUSY;
+ if (!isGoodInitializerOrBadObject (cond))
+ {
+ condInitializationLock.unlock ();
+ return EBUSY;
+ }
*cond = new pthread_cond (attr ? (*attr) : NULL);
-
- if (!pthread_cond::isGoodObject (cond))
+ if (!isGoodObject (cond))
{
delete (*cond);
*cond = NULL;
+ condInitializationLock.unlock ();
return EAGAIN;
}
-
+ condInitializationLock.unlock ();
return 0;
}
@@ -2044,7 +2072,7 @@ int
__pthread_cond_broadcast (pthread_cond_t *cond)
{
if (pthread_cond::isGoodInitializer (cond))
- __pthread_cond_init (cond, NULL);
+ pthread_cond::init (cond, NULL);
if (!pthread_cond::isGoodObject (cond))
return EINVAL;
@@ -2057,7 +2085,7 @@ int
__pthread_cond_signal (pthread_cond_t *cond)
{
if (pthread_cond::isGoodInitializer (cond))
- __pthread_cond_init (cond, NULL);
+ pthread_cond::init (cond, NULL);
if (!pthread_cond::isGoodObject (cond))
return EINVAL;
@@ -2078,7 +2106,7 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex,
pthread_mutex::init (mutex, NULL);
themutex = mutex;
if (pthread_cond::isGoodInitializer (cond))
- __pthread_cond_init (cond, NULL);
+ pthread_cond::init (cond, NULL);
if (!pthread_mutex::isGoodObject (themutex))
return EINVAL;
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index d33750c..a4a4f15 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -121,6 +121,16 @@ void AssertResourceOwner (int, int);
#endif
}
+class nativeMutex
+{
+public:
+ bool init ();
+ bool lock ();
+ void unlock ();
+private:
+ HANDLE theHandle;
+};
+
class per_process;
class pinfo;
@@ -288,9 +298,9 @@ public:
class pthread_mutex:public verifyable_object
{
public:
- static bool isGoodObject(pthread_mutex_t const *);
- static bool isGoodInitializer(pthread_mutex_t const *);
- static bool isGoodInitializerOrObject(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 isGoodInitializerOrBadObject (pthread_mutex_t const *mutex);
static void initMutex ();
static int init (pthread_mutex_t *, const pthread_mutexattr_t *);
@@ -309,15 +319,8 @@ public:
pthread_mutex (pthread_mutexattr * = NULL);
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
~pthread_mutex ();
+
private:
- class nativeMutex {
- public:
- bool init();
- bool lock();
- void unlock();
- private:
- HANDLE theHandle;
- };
static nativeMutex mutexInitializationLock;
};
@@ -432,9 +435,13 @@ public:
class pthread_cond:public verifyable_object
{
public:
- static bool isGoodObject(pthread_cond_t const *);
- static bool isGoodInitializer(pthread_cond_t const *);
- static bool isGoodInitializerOrObject(pthread_cond_t const *);
+ static bool isGoodObject (pthread_cond_t const *);
+ static bool isGoodInitializer (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;
LONG waiting;
LONG ExitingWait;
@@ -450,6 +457,9 @@ public:
pthread_cond (pthread_condattr *);
~pthread_cond ();
+
+private:
+ static nativeMutex condInitializationLock;
};
class pthread_once
@@ -559,8 +569,6 @@ void *__pthread_getspecific (pthread_key_t key);
/* Thead synchroniation */
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_broadcast (pthread_cond_t * cond);
int __pthread_condattr_init (pthread_condattr_t * condattr);