]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOLocks.cpp
xnu-1456.1.26.tar.gz
[apple/xnu.git] / iokit / Kernel / IOLocks.cpp
index 988e015294005fb79b0d6f014750178a1ac1b066..a61f6a326ac7d3bd1509fcb4d02d1060fff514f7 100644 (file)
  * 
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
-/*
- * Copyright (c) 1998 Apple Computer, Inc.  All rights reserved. 
- *
- * HISTORY
- *
- */
-
-
-#define        IOLOCKS_CPP     1
 
 #include <IOKit/system.h>
 
@@ -195,7 +186,6 @@ int IORecursiveLockSleep(IORecursiveLock *_lock, void *event, UInt32 interType)
     int res;
 
     assert(lock->thread == IOThreadSelf());
-    assert(lock->count == 1 || interType == THREAD_UNINT);
     
     lock->count = 0;
     lock->thread = 0;
@@ -210,6 +200,29 @@ int IORecursiveLockSleep(IORecursiveLock *_lock, void *event, UInt32 interType)
     return res;
 }
 
+int    IORecursiveLockSleepDeadline( IORecursiveLock * _lock, void *event,
+                                  AbsoluteTime deadline, UInt32 interType)
+{
+    _IORecursiveLock * lock = (_IORecursiveLock *)_lock;
+    UInt32 count = lock->count;
+    int res;
+
+    assert(lock->thread == IOThreadSelf());
+    
+    lock->count = 0;
+    lock->thread = 0;
+    res = lck_mtx_sleep_deadline(lock->mutex, LCK_SLEEP_DEFAULT, (event_t) event, 
+                                                                (wait_interrupt_t) interType, __OSAbsoluteTime(deadline));
+
+    // 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;
+}
+
 void IORecursiveLockWakeup(IORecursiveLock *, void *event, bool oneThread)
 {
     thread_wakeup_prim((event_t) event, oneThread, THREAD_AWAKENED);