- if (!(mKernelPort = ::IORegisterForSystemPower(this, &mPortRef, ioCallback, &mHandle)))
- UnixError::throwMe(EINVAL); // no clue
-
- setupDarkWake();
+ if (!(mKernelPort = ::IORegisterForSystemPower(this, &mPortRef, ioCallback, &mHandle)))
+ UnixError::throwMe(EINVAL); // no clue
+
+ mIOPMqueue = dispatch_queue_create("com.apple.security.IOPowerWatcher", NULL);
+ if (mIOPMqueue == NULL)
+ return;
+
+ // Running in background since this will wait for the power
+ // management in configd and we are not willing to block on
+ // that, power events will come in when they do.
+ mDarkWakeGroup = dispatch_group_create();
+ dispatch_group_enter(mDarkWakeGroup);
+ dispatch_async(mIOPMqueue, ^ { setupDarkWake(); });