futex (Fast Userspace Mutex)ο
Header: udo/futex.h
Table of contents (click to go)ο
Macrosο
Enumsο
Unionsο
Structsο
Functionsο
API Documentationο
udo_futex_create_infoο
Structure passed to
udo_futex_create() usedto define size of shared memory and amount of
futexes contained at the start of shared memory.
udo_futex_createο
-
udo_atomic_u32 *udo_futex_create(const void *futex_info);ο
Allocates shared memory space that may be used
to store a futex. This function usage should
be limited to processes/threads that were created
via fork() or pthread_create(). For processes
created without fork() (i.e separate application)
see shm.c implementation. By default all futexes
are initialize in the locked state.
Futex Memory Block (3 futexes)ο Data Stored
Offset In Bytes
Byte Size
Initial Value
P1 Futex
0
4
1 (locked)
P2 Futex
4
4
1 (locked)
P3 Futex
8
4
1 (locked)
Param
Decription
futex_info
Implementation uses a pointer to astructudo_futex_create_info.
- Returns:
on success: Pointer to audo_atomic_u32on failure:NULL
udo_futex_lockο
-
void udo_futex_lock(udo_atomic_u32 *fux);ο
Atomically updates futex value to the locked state.
If value canβt be changed inform kernel that a
process/thread needs to be put to sleep. Sets errno
to EINTR if a call to
udo_futex_unlock_force()is made.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.
udo_futex_waitο
-
void udo_futex_wait(udo_atomic_u32 *fux, const uint32_t desired);ο
Wait until the futex value is in the desired state.
If value canβt be changed inform kernel that a
process/thread needs to be put to sleep. Sets errno to
EINTR if a call to
udo_futex_unlock_force()is made.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.desired
Must pass value to wait on.
udo_futex_wait_condο
-
udo_futex_wait_cond(fux, cond)ο
Wait until the the conditional expression
is meet. Then inform kernel to wake up all
processes/threads watching the futex. The
value at the futex isnβt required when
using this macro. Sets errno to EINTR if
a call to
udo_futex_unlock_force() is made.NOTE: This macro wraps the function
void p_udo_futex_wait_cond(udo_atomic_u32 *fux).
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.cond
If statement conditional expressionto meet. If condition not meet informkernel to wake up all processes/threadswatching the futex.
udo_futex_unlockο
-
void udo_futex_unlock(udo_atomic_u32 *fux);ο
Atomically update futex value to the unlocked state.
Then inform kernel to wake up all processes/threads
watching the futex.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.
udo_futex_unlock_forceο
-
void udo_futex_unlock_force(udo_atomic_u32 *fux);ο
Atomically update futex value to the force unlocked state.
Then inform kernel to wake up all processes/threads
watching the futex. When force unlocking if a
process/thread is waiting on the lock. Process/thread
will exit setting errno to EINTR. Recommended to use
function in a signal handler.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.
udo_futex_wakeο
-
void udo_futex_wake(udo_atomic_u32 *fux, const uint32_t desired);ο
Atomically update futex value to the desired state.
Then inform kernel to wake up all processes/threads
watching the futex.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.desired
Must pass value to store in futex.
udo_futex_wake_condο
-
void udo_futex_wake_cond(udo_atomic_u32 *fux);ο
Wakes all processes/threads waiting
on a specific conditional expression
to be meet.
Conditional expressions may be set
with a call to
udo_futex_wait_cond.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.
udo_futex_destroyο
-
void udo_futex_destroy(udo_atomic_u32 *fux, const size_t size);ο
Frees any allocated memory and closes FDβs (if open)
created after
udo_futex_create() call.
Param
Decription
fux
Pointer to 32-bit unsigned integerstoring futex value.size
Size of shared memory block.