* 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.
This commit is contained in:
@ -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;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user