-void
-_Jv_MutexInit (_Jv_Mutex_t *mu)
-{
-#ifdef HAVE_RECURSIVE_MUTEX
- pthread_mutexattr_t *val = NULL;
-
-#if defined (HAVE_PTHREAD_MUTEXATTR_SETTYPE)
- pthread_mutexattr_t attr;
-
- // If this is slow, then allocate it statically and only initialize
- // it once.
- pthread_mutexattr_init (&attr);
- pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
- val = &attr;
-#elif defined (HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
- pthread_mutexattr_t attr;
- pthread_mutexattr_init (&attr);
- pthread_mutexattr_setkind_np (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
- val = &attr;
-#endif
-
- pthread_mutex_init (_Jv_PthreadGetMutex (mu), val);
-#ifdef PTHREAD_MUTEX_IS_STRUCT
- mu->count = 0;
-#endif
-
-#if defined (HAVE_PTHREAD_MUTEXATTR_SETTYPE) || defined (HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
- pthread_mutexattr_destroy (&attr);
-#endif
-
-#else /* HAVE_RECURSIVE_MUTEX */
-
- // No recursive mutex, so simulate one.
- pthread_mutex_init (&mu->mutex, NULL);
- pthread_mutex_init (&mu->mutex2, NULL);
- pthread_cond_init (&mu->cond, 0);
+ if (cv->first == NULL)
+ cv->first = current;
+ else
+ for (_Jv_Thread_t *t = cv->first;; t = t->next)
+ {
+ if (t->next == NULL)
+ {
+ t->next = current;
+ break;
+ }
+ }
+
+ // Record the current lock depth, so it can be restored when we re-aquire it.
+ int count = mu->count;
+
+ // Release the monitor mutex.