#include <os/lock.h>
os/lock.h
@header
Low-level lock API.
macroOS_LOCK_API_VERSION
#define OS_LOCK_API_VERSION 20160309
macroOS_UNFAIR_LOCK_AVAILABILITY
#define OS_UNFAIR_LOCK_AVAILABILITY __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
structos_unfair_lock_s
| uint32_t | _os_unfair_lock_opaque |
typedefos_unfair_lock
typedef struct os_unfair_lock_s os_unfair_lock;
typedefos_unfair_lock_t
typedef struct os_unfair_lock_s * os_unfair_lock_t;
macroOS_UNFAIR_LOCK_INIT
#define OS_UNFAIR_LOCK_INIT ((os_unfair_lock){0})
functionos_unfair_lock_lock
OS_UNFAIR_LOCK_AVAILABILITY OS_EXPORT OS_NOTHROW OS_NONNULL_ALL OS_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock.performWhileLocked() for async-safe scoped locking") void os_unfair_lock_lock( os_unfair_lock_t lock )
@function os_unfair_lock_lock
@abstract Locks an os_unfair_lock.
@param lock
Pointer to an os_unfair_lock.
functionos_unfair_lock_trylock
OS_UNFAIR_LOCK_AVAILABILITY OS_EXPORT OS_NOTHROW OS_WARN_RESULT OS_NONNULL_ALL OS_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock.tryPerformWhileLocked() for async-safe scoped locking") bool os_unfair_lock_trylock( os_unfair_lock_t lock )
@function os_unfair_lock_trylock
@abstract Locks an os_unfair_lock if it is not already locked.
@discussion It is invalid to surround this function with a retry loop, if this function
returns false, the program must be able to proceed without having acquired
the lock, or it must call os_unfair_lock_lock() directly (a retry loop around
os_unfair_lock_trylock() amounts to an inefficient implementation of
os_unfair_lock_lock() that hides the lock waiter from the system and prevents
resolution of priority inversions).
@param lock
Pointer to an os_unfair_lock.
@result Returns true if the lock was succesfully locked and false if the lock was
already locked.
functionos_unfair_lock_unlock
OS_UNFAIR_LOCK_AVAILABILITY OS_EXPORT OS_NOTHROW OS_NONNULL_ALL OS_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock.performWhileLocked() for async-safe scoped locking") void os_unfair_lock_unlock( os_unfair_lock_t lock )
@function os_unfair_lock_unlock
@abstract Unlocks an os_unfair_lock.
@param lock
Pointer to an os_unfair_lock.
functionos_unfair_lock_assert_owner
OS_UNFAIR_LOCK_AVAILABILITY OS_EXPORT OS_NOTHROW OS_NONNULL_ALL void os_unfair_lock_assert_owner( const os_unfair_lock *lock )
@function os_unfair_lock_assert_owner
@abstract Asserts that the calling thread is the current owner of the specified
unfair lock.
@discussion If the lock is currently owned by the calling thread, this function returns.
If the lock is unlocked or owned by a different thread, this function
asserts and terminates the process.
@param lock
Pointer to an os_unfair_lock.
functionos_unfair_lock_assert_not_owner
OS_UNFAIR_LOCK_AVAILABILITY OS_EXPORT OS_NOTHROW OS_NONNULL_ALL void os_unfair_lock_assert_not_owner( const os_unfair_lock *lock )
@function os_unfair_lock_assert_not_owner
@abstract Asserts that the calling thread is not the current owner of the specified
unfair lock.
@discussion If the lock is unlocked or owned by a different thread, this function
returns.
If the lock is currently owned by the current thread, this function asserts
and terminates the process.
@param lock
Pointer to an os_unfair_lock.
enumos_unfair_lock_flags_t
| OS_UNFAIR_LOCK_FLAG_NONE | 0 | |
| OS_UNFAIR_LOCK_FLAG_ADAPTIVE_SPIN | 262144 |
typedefos_unfair_lock_flags_t
typedef enum os_unfair_lock_flags_t os_unfair_lock_flags_t;
functionos_unfair_lock_lock_with_flags
__API_AVAILABLE(macos(15.0), ios(18.0), tvos(18.0), watchos(11.0), visionos(2.0)) OS_EXPORT OS_NOTHROW OS_NONNULL_ALL OS_SWIFT_UNAVAILABLE_FROM_ASYNC("Use OSAllocatedUnfairLock for async-safe scoped locking") void os_unfair_lock_lock_with_flags( os_unfair_lock_t lock, os_unfair_lock_flags_t flags )
@function os_unfair_lock_lock_with_flags
@abstract Locks an os_unfair_lock.
@param lock
Pointer to an os_unfair_lock.
@param flags
Flags to alter the behavior of the lock. See os_unfair_lock_flags_t.