I know this isn't your own code, but it's nevertheless buggy :)
Changes that make a difference in practice:
Check return value of semaphore_wait. This can return KERN_ABORTED if you halt in a debugger.
In wait_dequeue and wait_dequeue_timed, if the semaphore wait succeeds (indicating that an entry was enqueued) but try_dequeue then fails, print an error and abort, instead of just running try_dequeue in an infinite loop. (This condition indicates a bug in the semaphore code. I encountered the infinite loop in practice; I'm not sure I fixed the root cause, but at least now I'll know if I run into it again, rather than only noticing if I check for high CPU usage.)
Changes that probably won't make a difference in practice:
I know this isn't your own code, but it's nevertheless buggy :)
Changes that make a difference in practice:
semaphore_wait
. This can returnKERN_ABORTED
if you halt in a debugger.wait_dequeue
andwait_dequeue_timed
, if the semaphore wait succeeds (indicating that an entry was enqueued) buttry_dequeue
then fails, print an error and abort, instead of just runningtry_dequeue
in an infinite loop. (This condition indicates a bug in the semaphore code. I encountered the infinite loop in practice; I'm not sure I fixed the root cause, but at least now I'll know if I run into it again, rather than only noticing if I check for high CPU usage.)Changes that probably won't make a difference in practice:
semaphore_create
.semaphore_timedwait
.semaphore_signal
.