Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Pfaff <tpfaff@gmx.net>2003-03-18 22:39:21 +0300
committerThomas Pfaff <tpfaff@gmx.net>2003-03-18 22:39:21 +0300
commit2ff03dc2e01dbf0525ad32960612b5df0c6cb9f8 (patch)
treec8e7b4bceb8f6f175bb1c4bf6f34bbf331cec7e3 /winsup/cygwin/thread.h
parentdcd350f0ec963e59b91118ae437e5f783a283e94 (diff)
* include/pthread.h (PTHREAD_MUTEX_NORMAL): New define.
* thread.cc: Remove errno.h include. (pthread::precreate): Change internal mutex type to normal. (pthread_mutex::canBeUnlocked): Implement. (pthread_mutex::pthread_mutex): Initialize lock_counter with 0. (pthread_mutex::Lock): Rename to _Lock. Add self parameter. Change lock_counter logic. Update SetOwner call. (pthread_mutex::TryLock): Rename to _TryLock. Add self parameter. Change lock_counter logic. Update SetOwner call. (pthread_mutex::UnLock): Rename to _UnLock. Add self parameter. Change lock_counter logic. (pthread_mutex::Destroy): Rename to _Destroy. Update TryLock call. (pthread_mutex::SetOwner): Move to thread.h as inline. (pthread_mutex::LockRecursive): Ditto. (pthread_mutex::fixup_after_fork): Change lock_counter logic. (__pthread_mutexattr_settype): Add PTHREAD_MUTEX_NORMAL to valid types check. * thread.h: Include errno.h and limits.h. (MUTEX_LOCK_COUNTER_INITIAL): Remove. (MUTEX_OWNER_ANONYMOUS): New define. (pthread_mutex::canBeUnlocked): New static method. (pthread_mutex::lock_counter): Change type to unsigned long. (pthread_mutex::GetPthreadSelf): New method. (pthread_mutex::Lock): Call _Lock with pthread_self pointer. (pthread_mutex::TryLock): Call _TryLock with pthread_self pointer. (pthread_mutex::UnLock): Call _UnLock with pthread_self pointer. (pthread_mutex::Destroy): Call _Destroy with pthread_self pointer. (pthread_mutex::SetOwner): Moved from thread.cc as inline. (pthread_mutex::LockRecursive): Ditto. (pthread_mutex::_Lock): New method. (pthread_mutex::_TryLock): New method. (pthread_mutex::_UnLock): New method. (pthread_mutex::_Destroy): New method.
Diffstat (limited to 'winsup/cygwin/thread.h')
-rw-r--r--winsup/cygwin/thread.h57
1 files changed, 48 insertions, 9 deletions
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index 9e1405d61..bd911bd49 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -39,6 +39,8 @@ extern "C"
#else
#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
@@ -160,9 +162,9 @@ private:
#define PTHREAD_COND_MAGIC PTHREAD_MAGIC+5
#define PTHREAD_CONDATTR_MAGIC PTHREAD_MAGIC+6
#define SEM_MAGIC PTHREAD_MAGIC+7
-#define PTHREAD_ONCE_MAGIC PTHREAD_MAGIC+8;
+#define PTHREAD_ONCE_MAGIC PTHREAD_MAGIC+8
-#define MUTEX_LOCK_COUNTER_INITIAL (-1)
+#define MUTEX_OWNER_ANONYMOUS ((pthread_t) -1)
/* verifyable_object should not be defined here - it's a general purpose class */
@@ -304,10 +306,11 @@ public:
static bool isGoodInitializer (pthread_mutex_t const *);
static bool isGoodInitializerOrObject (pthread_mutex_t const *);
static bool isGoodInitializerOrBadObject (pthread_mutex_t const *mutex);
+ static bool canBeUnlocked (pthread_mutex_t const *mutex);
static void initMutex ();
static int init (pthread_mutex_t *, const pthread_mutexattr_t *);
- LONG lock_counter;
+ unsigned long lock_counter;
HANDLE win32_obj_id;
unsigned int recursion_counter;
LONG condwaits;
@@ -316,12 +319,43 @@ public:
int pshared;
class pthread_mutex * next;
- int Lock ();
- int TryLock ();
- int UnLock ();
- int Destroy ();
- void SetOwner ();
- int LockRecursive ();
+ pthread_t GetPthreadSelf () const
+ {
+ return PTHREAD_MUTEX_NORMAL == type ? MUTEX_OWNER_ANONYMOUS :
+ ::pthread_self ();
+ }
+
+ int Lock ()
+ {
+ return _Lock (GetPthreadSelf ());
+ }
+ int TryLock ()
+ {
+ return _TryLock (GetPthreadSelf ());
+ }
+ int UnLock ()
+ {
+ return _UnLock (GetPthreadSelf ());
+ }
+ int Destroy ()
+ {
+ return _Destroy (GetPthreadSelf ());
+ }
+
+ void SetOwner (pthread_t self)
+ {
+ recursion_counter = 1;
+ owner = self;
+ }
+
+ int LockRecursive ()
+ {
+ if (UINT_MAX == recursion_counter)
+ return EAGAIN;
+ ++recursion_counter;
+ return 0;
+ }
+
void fixup_after_fork ();
pthread_mutex (pthread_mutexattr * = NULL);
@@ -329,6 +363,11 @@ public:
~pthread_mutex ();
private:
+ int _Lock (pthread_t self);
+ int _TryLock (pthread_t self);
+ int _UnLock (pthread_t self);
+ int _Destroy (pthread_t self);
+
static nativeMutex mutexInitializationLock;
};