2 ms·
syscalls aren't public API on Darwin platforms (e.g. iOS, OS X). The only supported interface to syscalls is libc/libsystem. And I'm not aware of any equivalent
by eridius 11y ago
syscalls aren't public API on Darwin platforms (e.g. iOS, OS X). The only supported interface to syscalls is libc/libsystem. And I'm not aware of any equivalent to futex. So AFAIK there's no way to implement a userspace mutex that isn't just a wrapper around a system-provided mutex (e.g. pthread_mutex, or a serial libdispatch queue). And if you're wrapping pthread_mutex, adding a spinlock doesn't provide any benefit.
FWIW, libdispatch itself definitely uses Mach SPI. For example, skimming through the source, it calls thread_switch() using a non-public option (there's 3 non-public options to thread_switch now, two of which are intended for dealing with the QOS issues that my article talked about; the private os_lock_handoff_s that the objc runtime uses internally uses one called SWITCH_OPTION_OSLOCK_WAIT and libdispatch appears to use the other, SWITCH_OPTION_OSLOCK_DEPRESS, as well as the third option which was added just for libdispatch called SWITCH_OOPTION_DISPATCH_CONTENTION).