> Hi All,
> Can someone clarify the way the commandSleep function works for
> According to the document (both Xcode help and the Description
> in the Source), the following steps occur when commandSleep is called:
> OpenGate() is called
> Thread goes to sleep waiting for an Event
> on Event
> return to the thread context.
> Looking at the Source Code, commandSleep makes a call to
> IOEventSource's sleepGate which in turn calls IOWorkloop's
> sleepGate and it returns IORecursiveLockSleep().
> Where is the OpenGate or a counterpart Implemented ?
> In this process, is the OpenGate and the Sleep operation atomic (it
> does not seem to be the case). If its not atomic, wouldn't it be
> vulnerable to a context switch in be! tween, causing a
> situation where a CommandWakeup is called before the sleep happens !
The mechanism is explicitly designed to prevent this race, and it is
why you are not seeing the OpenGate operation at that level. The
actual lock operation is performed at a much lower level.
> What would be the best way to implement a commandSleep for a sub-
> Class of IOEventSource without the above problems.