+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>
Remove \n from calls to strace class printfs throughout.
return true;
}
-HANDLE pthread_mutex::mutexInitializationLock;
+pthread_mutex::nativeMutex pthread_mutex::mutexInitializationLock;
/* We can only be called once.
TODO: (no rush) use a non copied memory section to
void
pthread_mutex::initMutex ()
{
- mutexInitializationLock = CreateMutex (NULL, FALSE, NULL);
- if (!mutexInitializationLock)
- api_fatal ("Could not create win32 Mutex for pthread mutex static initializer support. The error code was %E");
-
+ if (!mutexInitializationLock.init())
+ api_fatal ("Could not create win32 Mutex for pthread mutex static initializer support.\n");
}
pthread_mutex::pthread_mutex (pthread_mutexattr *attr):verifyable_object (PTHREAD_MUTEX_MAGIC)
}
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
pthread_mutexattr::isGoodObject (pthread_mutexattr_t const * attr)
{
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
{
if (attr && !pthread_mutexattr::isGoodObject (attr) || check_valid_pointer (mutex))
return EINVAL;
- DWORD waitResult = WaitForSingleObject (mutexInitializationLock, INFINITE);
- if (waitResult != WAIT_OBJECT_0)
- {
- system_printf ("Received a unexpected wait result on mutexInitializationLock %d, %E", waitResult);
- return EINVAL;
- }
+ if (!mutexInitializationLock.lock())
+ return EINVAL;
/* FIXME: bugfix: we should check *mutex being a valid address */
if (isGoodObject (mutex))
{
- if (!ReleaseMutex (mutexInitializationLock))
- system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
+ mutexInitializationLock.unlock();
return EBUSY;
}
{
delete (*mutex);
*mutex = NULL;
- if (!ReleaseMutex (mutexInitializationLock))
- system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
+ mutexInitializationLock.unlock();
return EAGAIN;
}
- if (!ReleaseMutex (mutexInitializationLock))
- system_printf ("Received a unexpected result releasing mutexInitializationLock %E");
+ mutexInitializationLock.unlock();
return 0;
}