|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
POSIX implementation of the thread-level operations in serene/rt/fiber/thread.h, realised with pthreads. More...
Go to the source code of this file.
Macros | |
| #define | THREAD_LOG(FMT, ...) |
Functions | |
| static srn_thread_status_t | status_from_errno (int rc) |
| Map a pthreads return code onto the neutral status. | |
| static void * | posix_trampoline (void *arg) |
pthreads run a thread through a void *(*)(void *) routine, while the modeled operation runs a void (*)(void *). | |
| srn_thread_status_t | srn_thread_spawn (srn_thread_t *t, void(*fn)(void *), void *arg) |
Run fn(arg) on a new OS thread. | |
| srn_thread_status_t | srn_thread_join (srn_thread_t *t) |
Block until the thread started for t returns. | |
| srn_thread_status_t | srn_mutex_init (srn_mutex_t *m) |
| srn_thread_status_t | srn_mutex_lock (srn_mutex_t *m) |
| srn_thread_status_t | srn_mutex_unlock (srn_mutex_t *m) |
| srn_thread_status_t | srn_mutex_destroy (srn_mutex_t *m) |
| Release a mutex's resources. | |
| srn_thread_status_t | srn_cond_init (srn_cond_t *c) |
| srn_thread_status_t | srn_cond_wait (srn_cond_t *c, srn_mutex_t *m) |
Release m, sleep until notified, then re-acquire m before returning. | |
| srn_thread_status_t | srn_cond_notify_one (srn_cond_t *c) |
| Wake one waiter. | |
| srn_thread_status_t | srn_cond_notify_all (srn_cond_t *c) |
| Wake every waiter. | |
| srn_thread_status_t | srn_cond_destroy (srn_cond_t *c) |
| Release a condition's resources. | |
POSIX implementation of the thread-level operations in serene/rt/fiber/thread.h, realised with pthreads.
The pthreads mutex and condition functions return their error code as the return value and leave the global errno untouched. Every such code is mapped to an srn_thread_status_t so no pthread code escapes the public API. The raw code is also logged through THREAD_LOG, which is a debug-only diagnostic and not part of the interface.
Definition in file thread_posix.c.
| #define THREAD_LOG | ( | FMT, | |
| ... ) |
Definition at line 33 of file thread_posix.c.
|
static |
pthreads run a thread through a void *(*)(void *) routine, while the modeled operation runs a void (*)(void *).
This trampoline bridges the two: it reads the function and argument the spawn recorded on the thread, runs them, and returns the null pthreads expects.
Definition at line 57 of file thread_posix.c.
| srn_thread_status_t srn_cond_destroy | ( | srn_cond_t * | c | ) |
Release a condition's resources.
It must have no waiters, and must not be used again without a fresh srn_cond_init.
Definition at line 160 of file thread_posix.c.
| srn_thread_status_t srn_cond_init | ( | srn_cond_t * | c | ) |
Definition at line 123 of file thread_posix.c.
| srn_thread_status_t srn_cond_notify_all | ( | srn_cond_t * | c | ) |
Wake every waiter.
Definition at line 151 of file thread_posix.c.
| srn_thread_status_t srn_cond_notify_one | ( | srn_cond_t * | c | ) |
Wake one waiter.
Definition at line 142 of file thread_posix.c.
| srn_thread_status_t srn_cond_wait | ( | srn_cond_t * | c, |
| srn_mutex_t * | m ) |
Release m, sleep until notified, then re-acquire m before returning.
A wait can wake spuriously, so the caller must re-check its predicate in a loop.
Definition at line 132 of file thread_posix.c.
| srn_thread_status_t srn_mutex_destroy | ( | srn_mutex_t * | m | ) |
Release a mutex's resources.
The mutex must be unlocked and have no waiters, and must not be used again without a fresh srn_mutex_init.
Definition at line 114 of file thread_posix.c.
| srn_thread_status_t srn_mutex_init | ( | srn_mutex_t * | m | ) |
Definition at line 87 of file thread_posix.c.
| srn_thread_status_t srn_mutex_lock | ( | srn_mutex_t * | m | ) |
Definition at line 96 of file thread_posix.c.
| srn_thread_status_t srn_mutex_unlock | ( | srn_mutex_t * | m | ) |
Definition at line 105 of file thread_posix.c.
| srn_thread_status_t srn_thread_join | ( | srn_thread_t * | t | ) |
Block until the thread started for t returns.
Definition at line 77 of file thread_posix.c.
| srn_thread_status_t srn_thread_spawn | ( | srn_thread_t * | t, |
| void(* | fn )(void *), | ||
| void * | arg ) |
Run fn(arg) on a new OS thread.
Returns SRN_THREAD_OK, or a status describing why the thread could not be created. The caller owns t and must keep it alive until srn_thread_join returns.
Definition at line 63 of file thread_posix.c.
|
static |
Map a pthreads return code onto the neutral status.
Anything without a dedicated code (EDEADLK, EINVAL, ESRCH, and so on) becomes SRN_THREAD_ERROR. The precise code is recovered from the THREAD_LOG line at the call site.
Definition at line 38 of file thread_posix.c.