@@ -20,24 +20,24 @@ #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS -# import "mutex.h" +# import "OFPlainMutex.h" -static struct lock_s { - id object; - int count; - of_rmutex_t rmutex; - struct lock_s *next; +static struct Lock { + id object; + int count; + OFPlainRecursiveMutex rmutex; + struct Lock *next; } *locks = NULL; -static of_mutex_t mutex; +static OFPlainMutex mutex; OF_CONSTRUCTOR() { - if (of_mutex_new(&mutex) != 0) + if (OFPlainMutexNew(&mutex) != 0) OBJC_ERROR("Failed to create mutex!"); } #endif int @@ -45,48 +45,48 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct lock_s *lock; + struct Lock *lock; - if (of_mutex_lock(&mutex) != 0) + if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; - if (of_mutex_unlock(&mutex) != 0) + if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); - if (of_rmutex_lock(&lock->rmutex) != 0) + if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); return 0; } /* Create a new lock */ if ((lock = malloc(sizeof(*lock))) == NULL) OBJC_ERROR("Failed to allocate memory for mutex!"); - if (of_rmutex_new(&lock->rmutex) != 0) + if (OFPlainRecursiveMutexNew(&lock->rmutex) != 0) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; lock->next = locks; locks = lock; - if (of_mutex_unlock(&mutex) != 0) + if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); - if (of_rmutex_lock(&lock->rmutex) != 0) + if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); #endif return 0; } @@ -96,26 +96,26 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct lock_s *lock, *last = NULL; + struct Lock *lock, *last = NULL; - if (of_mutex_lock(&mutex) != 0) + if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } - if (of_rmutex_unlock(&lock->rmutex) != 0) + if (OFPlainRecursiveMutexUnlock(&lock->rmutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (--lock->count == 0) { - if (of_rmutex_free(&lock->rmutex) != 0) + if (OFPlainRecursiveMutexFree(&lock->rmutex) != 0) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; if (locks == lock) @@ -122,16 +122,16 @@ locks = lock->next; free(lock); } - if (of_mutex_unlock(&mutex) != 0) + if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); return 0; } - OBJC_ERROR("objc_sync_exit() was called for an object not locked!"); + OBJC_ERROR("objc_sync_exit() was called for an unlocked object!"); #else return 0; #endif }