+ // closeGate is recursive needn't worry if we already hold the lock.
+ wl->closeGate();
+ sleepersP = (uintptr_t *) &reserved;
+
+ // If the command gate is disabled and we aren't on the workloop thread
+ // itself then sleep until we get enabled.
+ IOReturn res;
+ if (!wl->onThread()) {
+ while (!enabled) {
+ IOReturn sleepResult = kIOReturnSuccess;
+ if (workLoop) {
+ *sleepersP |= kSleepersWaitEnabled;
+ sleepResult = wl->sleepGate(&enabled, THREAD_INTERRUPTIBLE);
+ *sleepersP &= ~kSleepersWaitEnabled;
+ }
+ bool wakeupTearDown = (!workLoop || (0 != (*sleepersP & kSleepersRemoved)));
+ if ((kIOReturnSuccess != sleepResult) || wakeupTearDown) {
+ wl->openGate();
+
+ if (wakeupTearDown) {
+ wl->wakeupGate(sleepersP, false); // No further resources used
+ }
+ return kIOReturnAborted;
+ }
+ }
+ }