- // 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;
+ if (0 == (--lock->count)) {
+ lock->thread = NULL;
+ lck_mtx_unlock( &lock->mutex );
+ }
+}
+
+boolean_t
+IORecursiveLockHaveLock( const IORecursiveLock * _lock)
+{
+ _IORecursiveLock * lock = (_IORecursiveLock *)_lock;
+
+ return lock->thread == IOThreadSelf();
+}
+
+int
+IORecursiveLockSleep(IORecursiveLock *_lock, void *event, UInt32 interType)
+{
+ _IORecursiveLock * lock = (_IORecursiveLock *)_lock;
+ UInt32 count = lock->count;
+ int res;
+
+ assert(lock->thread == IOThreadSelf());
+
+ lock->count = 0;
+ lock->thread = NULL;
+ res = lck_mtx_sleep(&lock->mutex, LCK_SLEEP_PROMOTED_PRI, (event_t) event, (wait_interrupt_t) 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 == NULL);
+ assert(lock->count == 0);
+ lock->thread = IOThreadSelf();
+ lock->count = count;
+ 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 = NULL;
+ res = lck_mtx_sleep_deadline(&lock->mutex, LCK_SLEEP_PROMOTED_PRI, (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 == NULL);
+ assert(lock->count == 0);
+ lock->thread = IOThreadSelf();
+ lock->count = count;
+ return res;