2002-09-30 Robert Collins <rbtcollins@hotmail.com>

* thread.cc (pthread_mutex::initMutex): Use the wrapper init call.
        (pthread_mutex::nativeMutex::init): Implement.
        (pthread_mutex::nativeMutex::lock): Ditto.
        (pthread_mutex::nativeMutex::unlock): Ditto.
        (pthread_mutex::init): Use the wrapper lock and unlockcalls.
        * thread.h (pthread_mutex): Move mutexInitializationLock into a
        nativeMutex wrapper class.
This commit is contained in:
Robert Collins 2002-09-30 11:43:43 +00:00
parent 1f3e9931a5
commit 06175d0acd
3 changed files with 58 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2002-09-30 Robert Collins <rbtcollins@hotmail.com>
* thread.cc (pthread_mutex::initMutex): Use the wrapper init call.
(pthread_mutex::nativeMutex::init): Implement.
(pthread_mutex::nativeMutex::lock): Ditto.
(pthread_mutex::nativeMutex::unlock): Ditto.
(pthread_mutex::init): Use the wrapper lock and unlockcalls.
* thread.h (pthread_mutex): Move mutexInitializationLock into a
nativeMutex wrapper class.
2002-09-30 Christopher Faylor <cgf@redhat.com> 2002-09-30 Christopher Faylor <cgf@redhat.com>
Remove \n from calls to strace class printfs throughout. Remove \n from calls to strace class printfs throughout.

View File

@ -1097,7 +1097,7 @@ pthread_mutex::isGoodInitializerOrObject (pthread_mutex_t const *mutex)
return true; return true;
} }
HANDLE pthread_mutex::mutexInitializationLock; pthread_mutex::nativeMutex 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
@ -1105,10 +1105,8 @@ HANDLE pthread_mutex::mutexInitializationLock;
void void
pthread_mutex::initMutex () pthread_mutex::initMutex ()
{ {
mutexInitializationLock = CreateMutex (NULL, FALSE, NULL); if (!mutexInitializationLock.init())
if (!mutexInitializationLock) api_fatal ("Could not create win32 Mutex for pthread mutex static initializer support.\n");
api_fatal ("Could not create win32 Mutex for pthread mutex static initializer support. The error code was %E");
} }
pthread_mutex::pthread_mutex (pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC) pthread_mutex::pthread_mutex (pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC)
@ -1214,6 +1212,37 @@ pthread_mutex::fixup_after_fork ()
#endif #endif
} }
bool
pthread_mutex::nativeMutex::init()
{
theHandle = CreateMutex (NULL, 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)
{ {
@ -2222,18 +2251,13 @@ pthread_mutex::init (pthread_mutex_t *mutex,
{ {
if (attr && !pthread_mutexattr::isGoodObject (attr) || check_valid_pointer (mutex)) if (attr && !pthread_mutexattr::isGoodObject (attr) || check_valid_pointer (mutex))
return EINVAL; return EINVAL;
DWORD waitResult = WaitForSingleObject (mutexInitializationLock, INFINITE); if (!mutexInitializationLock.lock())
if (waitResult != WAIT_OBJECT_0)
{
system_printf ("Received a unexpected wait result on mutexInitializationLock %d, %E", waitResult);
return EINVAL; return EINVAL;
}
/* FIXME: bugfix: we should check *mutex being a valid address */ /* FIXME: bugfix: we should check *mutex being a valid address */
if (isGoodObject (mutex)) if (isGoodObject (mutex))
{ {
if (!ReleaseMutex (mutexInitializationLock)) mutexInitializationLock.unlock();
system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
return EBUSY; return EBUSY;
} }
@ -2242,12 +2266,10 @@ pthread_mutex::init (pthread_mutex_t *mutex,
{ {
delete (*mutex); delete (*mutex);
*mutex = NULL; *mutex = NULL;
if (!ReleaseMutex (mutexInitializationLock)) mutexInitializationLock.unlock();
system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
return EAGAIN; return EAGAIN;
} }
if (!ReleaseMutex (mutexInitializationLock)) mutexInitializationLock.unlock();
system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
return 0; return 0;
} }

View File

@ -309,7 +309,15 @@ public:
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *); pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
~pthread_mutex (); ~pthread_mutex ();
private: private:
static HANDLE mutexInitializationLock; class nativeMutex {
public:
bool init();
bool lock();
void unlock();
private:
HANDLE theHandle;
};
static nativeMutex mutexInitializationLock;
}; };
class pthread:public verifyable_object class pthread:public verifyable_object