61dc808
diff -up allegro-4.4.2/src/unix/uthreads.c~ allegro-4.4.2/src/unix/uthreads.c
61dc808
--- allegro-4.4.2/src/unix/uthreads.c~	2009-11-22 02:17:42.000000000 +0100
61dc808
+++ allegro-4.4.2/src/unix/uthreads.c	2014-10-29 15:00:24.977558559 +0100
61dc808
@@ -303,32 +303,27 @@ struct bg_manager _bg_man_pthreads = {
61dc808
 
61dc808
 
61dc808
 
61dc808
-/* custom mutex that supports nested locking */
61dc808
-struct my_mutex {
61dc808
-   int lock_count;                /* level of nested locking     */
61dc808
-   pthread_t owner;               /* thread which owns the mutex */
61dc808
-   pthread_mutex_t actual_mutex;  /* underlying mutex object     */
61dc808
-};
61dc808
-
61dc808
-
61dc808
-
61dc808
 /* _unix_create_mutex:
61dc808
  *  Creates a mutex and returns a pointer to it.
61dc808
  */
61dc808
 void *_unix_create_mutex(void)
61dc808
 {
61dc808
-   struct my_mutex *mx;
61dc808
+   pthread_mutex_t *mx;
61dc808
+   pthread_mutexattr_t attr;
61dc808
 
61dc808
-   mx = _AL_MALLOC(sizeof(struct my_mutex));
61dc808
+   mx = _AL_MALLOC(sizeof(pthread_mutex_t));
61dc808
    if (!mx) {
61dc808
       *allegro_errno = ENOMEM;
61dc808
       return NULL;
61dc808
    }
61dc808
 
61dc808
-   mx->lock_count = 0;
61dc808
-   mx->owner = (pthread_t) 0;
61dc808
+   pthread_mutexattr_init(&attr);
61dc808
+   if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
61dc808
+       abort(); /* XXX */
61dc808
 
61dc808
-   pthread_mutex_init(&mx->actual_mutex, NULL);
61dc808
+   pthread_mutex_init(mx, &attr);
61dc808
+
61dc808
+   pthread_mutexattr_destroy(&attr);
61dc808
 
61dc808
    return (void *)mx;
61dc808
 }
61dc808
@@ -340,11 +335,8 @@ void *_unix_create_mutex(void)
61dc808
  */
61dc808
 void _unix_destroy_mutex(void *handle)
61dc808
 {
61dc808
-   struct my_mutex *mx = (struct my_mutex *)handle;
61dc808
-
61dc808
-   pthread_mutex_destroy(&mx->actual_mutex);
61dc808
-
61dc808
-   _AL_FREE(mx);
61dc808
+   pthread_mutex_destroy(handle);
61dc808
+   _AL_FREE(handle);
61dc808
 }
61dc808
 
61dc808
 
61dc808
@@ -354,14 +346,7 @@ void _unix_destroy_mutex(void *handle)
61dc808
  */
61dc808
 void _unix_lock_mutex(void *handle)
61dc808
 {
61dc808
-   struct my_mutex *mx = (struct my_mutex *)handle;
61dc808
-
61dc808
-   if (mx->owner != pthread_self()) {
61dc808
-      pthread_mutex_lock(&mx->actual_mutex);
61dc808
-      mx->owner = pthread_self();      
61dc808
-   }
61dc808
-
61dc808
-   mx->lock_count++;
61dc808
+   pthread_mutex_lock(handle);
61dc808
 }
61dc808
 
61dc808
 
61dc808
@@ -371,14 +356,7 @@ void _unix_lock_mutex(void *handle)
61dc808
  */
61dc808
 void _unix_unlock_mutex(void *handle)
61dc808
 {
61dc808
-   struct my_mutex *mx = (struct my_mutex *)handle;
61dc808
-
61dc808
-   mx->lock_count--;
61dc808
-
61dc808
-   if (mx->lock_count == 0) {
61dc808
-      mx->owner = (pthread_t) 0;
61dc808
-      pthread_mutex_unlock(&mx->actual_mutex);
61dc808
-   }
61dc808
+   pthread_mutex_unlock(handle);
61dc808
 }
61dc808
 
61dc808
 #endif	/* ALLEGRO_HAVE_LIBPTHREAD */