Loading...
iokit/Kernel/IOLocks.cpp xnu-123.5 xnu-517.7.7
--- xnu/xnu-123.5/iokit/Kernel/IOLocks.cpp
+++ xnu/xnu-517.7.7/iokit/Kernel/IOLocks.cpp
@@ -49,8 +49,6 @@
 
 void	IOLockInitWithState( IOLock * lock, IOLockState state)
 {
-    mutex_init( lock, ETAP_IO_AHA);
-
     if( state == kIOLockStateLocked)
         IOLockLock( lock);
 }
@@ -96,7 +94,7 @@
     if( lock->thread == IOThreadSelf())
         lock->count++;
     else {
-        _mutex_lock( lock->mutex );
+        mutex_lock( lock->mutex );
         assert( lock->thread == 0 );
         assert( lock->count == 0 );
         lock->thread = IOThreadSelf();
@@ -112,7 +110,7 @@
         lock->count++;
 	return( true );
     } else {
-        if( _mutex_try( lock->mutex )) {
+        if( mutex_try( lock->mutex )) {
             assert( lock->thread == 0 );
             assert( lock->count == 0 );
             lock->thread = IOThreadSelf();
@@ -151,21 +149,16 @@
     assert(lock->thread == IOThreadSelf());
     assert(lock->count == 1 || interType == THREAD_UNINT);
     
-    assert_wait((event_t) event, (int) interType);
     lock->count = 0;
     lock->thread = 0;
-    mutex_unlock(lock->mutex);
-    
-    res = thread_block(0);
-
-    if (THREAD_AWAKENED == res) {
-        _mutex_lock(lock->mutex);
-        assert(lock->thread == 0);
-        assert(lock->count == 0);
-        lock->thread = IOThreadSelf();
-        lock->count = count;
-    }
-
+    res = thread_sleep_mutex((event_t) event, lock->mutex, (int) interType);
+
+    // Must re-establish the recursive lock no matter why we woke up
+    // otherwise we would potentially leave the return path corrupted.
+    assert(lock->thread == 0);
+    assert(lock->count == 0);
+    lock->thread = IOThreadSelf();
+    lock->count = count;
     return res;
 }