I’m looking for a wait/signal synchronization primitive in IO/Kit working like :
Thread1 : wait(myEvent) // Blocking thread1
Thread2 : wait(myEvent) // Blocking thread2
Thread3 : signal(myEvent) // Release one of thread1 or thread2
This can’t be done using an IOLock since the lock/unlock operations would be made from different threads, which is a bad idea according to some doc I’ve read.
Thread1, 2, 3 can be user threads or kernel threads.
I’d also like to have an optional time out with the wait operation.
Thanks for your help !
You want the function
IOLockSleepDeadline(), declared in<IOKit/IOLocks.h>.You set up a single
IOLocksomewhere withIOLockAlloc()before you begin. Then, threads 1 and 2 lock the IOLock withIOLockLock()and immediately relinquish the lock and go to sleep by callingIOLockSleepDeadline(). When thread 3 is ready, it callsIOLockWakeup()(withoneThread = trueif you only want to wake a single thread). This causes thread 1 or 2 to wake up and immediately acquire the lock (so they need to Unlock or sleep again).IOLockSleep()works similarly, but without the timeout.You can do something similar using the IOCommandGate’s commandSleep() method which may be more appropriate if your driver already is centred around an
IOWorkLoop.