As of macOS 10.12, OSSpinLock
has been deprecated. The XCode error messages urge me to use os_unfair_lock_unlock()
instead.
As a legacy of some open source stuff I'm relying on, I'm using RegexKitLite from 2010.
How can I convert the spin lock type? Simple unlocking and locking I can manage, but these comparisons are giving me headache:
if(rkl_cacheSpinLock != (OSSpinLock)0) { ... }
rkl_cacheSpinLock
is of type os_unfair_lock
and has been initialized. OSSpinLock seems to be of type int
, so this if-statement obviously won't work.
Could anyone point me towards the right way of approaching this? I'm not too familiar with C, and don't really understand arithmetics of pointers.
EDIT
After learning a bit about C, I came to understood typecasting. I came up with a solution that seems to work. My understanding of OS functionality on this level is nonexistent. The os_unfair_lock is not too well documented for dummies, but it looks like I didn't break anything.
if (rkl_cacheSpinLock._os_unfair_lock_opaque != 0) { ... }
Seems like no one ever took the time to answer your question so here goes:
#include <os/lock.h>
void foo()
{
os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
os_unfair_lock_lock(&lock);
/* Your critical section here */
os_unfair_lock_unlock(&lock);
}
Please refer to the documentation for more details on restrictions regarding where you should lock and unlock (tldr: it has to be same thread that locks and unlocks).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With