Locks¶
An API for creating and using a software lock/mutex.
Defines
-
METAL_LOCK_BACKOFF_CYCLES
¶
-
METAL_LOCK_BACKOFF_EXPONENT
¶
-
METAL_LOCK_DECLARE
(name)¶ Declare a lock.
Locks must be declared with METAL_LOCK_DECLARE to ensure that the lock is linked into a memory region which supports atomic memory operations.
Functions
-
__inline__ int
metal_lock_init
(struct metal_lock *lock)¶ Initialize a lock.
If the lock cannot be initialized, attempts to take or give the lock will result in a Store/AMO access fault.
- Return
0 if the lock is successfully initialized. A non-zero code indicates failure.
- Parameters
lock
: The handle for a lock
-
__inline__ int
metal_lock_take
(struct metal_lock *lock)¶ Take a lock.
If the lock initialization failed, attempts to take a lock will result in a Store/AMO access fault.
- Return
0 if the lock is successfully taken
- Parameters
lock
: The handle for a lock
-
__inline__ int
metal_lock_give
(struct metal_lock *lock)¶ Give back a held lock.
If the lock initialization failed, attempts to give a lock will result in a Store/AMO access fault.
- Return
0 if the lock is successfully given
- Parameters
lock
: The handle for a lock
-
struct
metal_lock
¶ - #include <lock.h>
A handle for a lock.