Godfrey van der Linden writes:
> You can still use the interrupt disable code and a mutex lock,
> IOSimpleLockLock... is pretty heavy weight and you are much better
> off using the mutex based locks rather than the simple locks, also
> the interrupt disable is much better for the system as a whole.
Actually, I think there is a better way which does not involve any
locks or interrupt disabling whatsoever. The only reason that
we need a lock or interrupt disable is to protect against a wakeup
arriving just before the sleeper puts himself on a wait queue.
In a much older driver, I used to use the appended code. But I need
to figre out what to do about clear_wait() disappearing. I wonder
if just a plain thread_wakeup_one(s) from the sleeper's context,
followed by a thread_block() would work.
And I also need to check the assert_wait() return value..a
Drew
my_sleep(my_sleep_t *s)
{
int result;
/* do we need to sleep? */
while (s->wake_cnt <= 0) {
/* put ourself on wait queue */
assert_wait (s, THREAD_ABORTSAFE);
/* don't sleep if interrupt raced with
wait queue insertion */
if (s->wake_cnt > 0) {
clear_wait (current_thread (), 0);
goto woke;
}
/* sleep until the event arrives or until we are interrupted */
result = thread_block (NULL);
if (result != THREAD_AWAKENED)
return MY_SLEEP_INTERRUPTED;
}
woke:
OSDecrementAtomic (&s->wake_cnt);
return MY_SLEEP_WOKE;
}
my_wakeup(my_sleep_t *s)
{
OSIncrementAtomic (&s->wake_cnt);
thread_wakeup_one (s);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/email@hidden
This email sent to email@hidden