What are you actually trying to do? If you want to acquire a lock and then execute code in the critical section which might block, you should use a mutex. On x86, kernel mutexes have an adaptive spin before they block on contention, so in practice critical sections of a few instructions should not cause other contending threads to enter the scheduler. Shantonu
On Sep 3, 2016, at 5:44 PM, John Kraft <jfk@uaudio.com> wrote:
We use IOSimpleLocks from the IOKit for this. These are just wrappers around the lck primitives, though.
________________________________________ From: darwin-kernel-bounces+jfk=uaudio.com@lists.apple.com <darwin-kernel-bounces+jfk=uaudio.com@lists.apple.com> on behalf of Adriaan van Os <gpc@microbizz.nl> Sent: Saturday, September 3, 2016 2:13 PM To: darwin-kernel@lists.apple.com Subject: Holding a spinlock
The Kernel Programming Guide in the Synchronization Primitives chapter says the following in the Locks section, Spinlocks subsection
Note that a thread may not block while holding a spinlock, because that could cause deadlock. Further, preemption is disabled on a given processor while a spinlock is held.
I assume the code will be something like (in Linux <http://www.makelinux.net/books/lkd2/ch06lev1sec7>)
local_irq_disable(); spin .... local_irq_enable();
However, I haven't been able to locate the code that does this or similar, at least not in osfmk/kern/locks.c. What is the recommended practice on Mac OS X ? I mean, apart from using the lck_ functions, who are not practical to use in my case. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-kernel/ssen%40apple.com
This email sent to ssen@apple.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
Shantonu Sen