|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
Go to the source code of this file.
Macros | |
| #define | SRN_MUTEX_HELD_WITH_NO_WAITER (&srn_mutex_held_marker) |
Functions | |
| static bool | srn_fiber_mutex_suspend (srn_fiber_t *self, void *arg) |
| Suspend commit function for a contended srn_fiber_mutex_lock. | |
| void | srn_fiber_mutex_init (srn_fiber_mutex_t *m) |
| Initialise m to the unlocked state. | |
| void | srn_fiber_mutex_lock (srn_fiber_mutex_t *m) |
| Acquire m. | |
| void | srn_fiber_mutex_unlock (srn_fiber_mutex_t *m) |
| Release m. | |
Variables | |
| static srn_fiber_t | srn_mutex_held_marker |
| Marker stored in srn_fiber_mutex_t.state to mean the lock is held with no waiter queued. | |
| #define SRN_MUTEX_HELD_WITH_NO_WAITER (&srn_mutex_held_marker) |
| void srn_fiber_mutex_init | ( | srn_fiber_mutex_t * | m | ) |
Initialise m to the unlocked state.
Definition at line 76 of file mutex.c.
| void srn_fiber_mutex_lock | ( | srn_fiber_mutex_t * | m | ) |
Acquire m.
If the lock is free it is taken at once, otherwise the calling fiber is suspended and resumes owning the lock, handed off directly by the unlocking fiber. Must be called from a running fiber.
Definition at line 81 of file mutex.c.
|
static |
Suspend commit function for a contended srn_fiber_mutex_lock.
Since the worker routine runs it once self is off its stack (see srn_fiber_suspend), so pushing self onto the waiter stack cannot race the running fiber.
If the lock has gone free since the fast path failed, it takes the lock and returns false to resume self at once. Otherwise it pushes self onto the incoming stack and returns true to stay suspended.
Definition at line 41 of file mutex.c.
| void srn_fiber_mutex_unlock | ( | srn_fiber_mutex_t * | m | ) |
Release m.
If any fibers are waiting, the longest waiting one is handed the lock and made ready, otherwise the lock is dropped. Must be called by the fiber that currently holds m.
Definition at line 99 of file mutex.c.
|
static |
Marker stored in srn_fiber_mutex_t.state to mean the lock is held with no waiter queued.
Only its address matters, its fields are never touched, so it only has to be a non-null srn_fiber_t pointer distinct from every real fiber. It also sits at the bottom of the incoming stack and terminates it, so a waiter push and the drain walk need no null special case.