21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
66#define R_ONCE_INIT { R_ONCE_STATE_INIT, NULL }
89#define R_TSS_INIT(notify) { (RDestroyNotify)(notify), { NULL } }
265#define r_thread_new(name, func, data) \
266 r_thread_new_full (name, NULL, func, data)
282#define r_thread_ref r_ref_ref
284#define r_thread_unref r_ref_unref
342R_API void r_thread_win32_dll_thread_detach (
void);
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
rpointer RMutex
Opaque mutex handle; initialise with r_mutex_init.
Definition rthreads.h:116
rpointer RRMutex
Opaque recursive-mutex handle; initialise with r_rmutex_init.
Definition rthreads.h:118
struct RThread RThread
Opaque, refcounted thread handle returned by r_thread_new_full.
Definition rthreads.h:131
ROnceState
Lifecycle states of an ROnce.
Definition rthreads.h:55
rpointer(* RThreadFunc)(rpointer data)
Thread entry-point signature.
Definition rthreads.h:129
rpointer RCond
Opaque condition-variable handle; initialise with r_cond_init.
Definition rthreads.h:122
rpointer r_call_once(ROnce *once, RThreadFunc f, rpointer a)
Run f exactly once across all threads, return its result.
rpointer RRWMutex
Opaque read/write-mutex handle; initialise with r_rwmutex_init.
Definition rthreads.h:120
@ R_ONCE_STATE_RUNNING
Definition rthreads.h:57
@ R_ONCE_STATE_INIT
Definition rthreads.h:56
@ R_ONCE_STATE_DONE
Definition rthreads.h:58
void r_mutex_init(RMutex *mutex)
Initialise a fresh RMutex.
void r_thread_exit(rpointer retval)
Exit the calling thread, returning retval to its joiner.
void r_thread_sleep(ruint sec)
Sleep the calling thread for sec whole seconds.
void r_cond_broadcast(RCond *cond)
Wake all threads waiting on cond.
void r_mutex_clear(RMutex *mutex)
Release OS resources held by mutex; must be unlocked first.
void r_rmutex_lock(RRMutex *mutex)
Acquire mutex (recursively for the owning thread).
void r_rmutex_init(RRMutex *mutex)
Initialise a fresh RRMutex.
void r_rwmutex_rdunlock(RRWMutex *mutex)
Release a previously-acquired read lock.
void r_mutex_unlock(RMutex *mutex)
Release mutex; the calling thread must currently hold it.
void r_tss_set(RTss *tss, rpointer data)
Set this thread's TSS value, freeing the previous one via the notify callback if any.
void r_thread_usleep(rulong microsec)
Sleep the calling thread for microsec microseconds.
rboolean r_thread_set_affinity(RThread *thread, const RBitset *cpuset)
Set thread's CPU-affinity mask.
void r_cond_clear(RCond *cond)
Release OS resources held by cond.
void r_cond_wait(RCond *cond, RMutex *mutex)
Atomically release mutex and wait until signalled, then reacquire mutex before returning.
int r_thread_kill(RThread *thread, int sig)
Send signal sig to thread (POSIX-style; thin wrapper over pthread_kill on Unix).
void r_rwmutex_init(RRWMutex *mutex)
Initialise a fresh RRWMutex.
void r_rmutex_unlock(RRMutex *mutex)
Release one nesting level of mutex.
void r_thread_yield(void)
Yield the calling thread's remaining quantum to the scheduler.
const rchar * r_thread_get_name(const RThread *thread)
Return the human-readable name thread was given at creation.
#define r_thread_unref
Drop a reference on thread (alias for r_ref_unref).
Definition rthreads.h:284
rboolean r_rwmutex_trywrlock(RRWMutex *mutex)
Try-lock variant of r_rwmutex_wrlock.
static void r_thread_join_unref(rpointer thread)
RDestroyNotify-compatible "join then unref" helper.
Definition rthreads.h:298
rboolean r_rwmutex_tryrdlock(RRWMutex *mutex)
Try-lock variant of r_rwmutex_rdlock.
RThread * r_thread_new_full(const rchar *name, const RBitset *cpuset, RThreadFunc func, rpointer data)
Spawn a new thread running func(data).
void r_rwmutex_rdlock(RRWMutex *mutex)
Acquire a shared read lock; blocks until no writer holds the lock.
rboolean r_mutex_trylock(RMutex *mutex)
Try to acquire mutex without blocking; TRUE on success.
rboolean r_thread_get_affinity(const RThread *thread, RBitset *cpuset)
Read thread's current CPU-affinity bitset into cpuset.
ruint r_thread_get_id(const RThread *thread)
Return thread's OS-assigned numeric ID.
rpointer r_thread_join(RThread *thread)
Wait for thread to terminate and return its result.
void r_rwmutex_wrunlock(RRWMutex *mutex)
Release a previously-acquired write lock.
void r_rwmutex_wrlock(RRWMutex *mutex)
Acquire an exclusive write lock; blocks until no reader or writer holds the lock.
RThread * r_thread_current(void)
Return the calling thread's RThread handle, or NULL if the calling thread was not created by rlib.
void r_cond_signal(RCond *cond)
Wake at least one thread waiting on cond.
void r_mutex_lock(RMutex *mutex)
Acquire mutex, blocking until available.
void r_cond_init(RCond *cond)
Initialise a fresh RCond.
void r_rmutex_clear(RRMutex *mutex)
Release OS resources held by mutex.
rpointer r_tss_get(RTss *tss)
Retrieve this thread's TSS value, or NULL if unset.
void r_rwmutex_clear(RRWMutex *mutex)
Release OS resources held by mutex.
rboolean r_rmutex_trylock(RRMutex *mutex)
Try-lock variant; see r_mutex_trylock.
unsigned long rulong
Unsigned long.
Definition rtypes.h:155
char rchar
Default character type (char).
Definition rtypes.h:137
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
unsigned int ruint
Unsigned int.
Definition rtypes.h:157
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
unsigned int ruint32
Unsigned 32-bit integer.
Definition rtypes.h:192
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
unsigned char ruint8
Unsigned 8-bit integer.
Definition rtypes.h:190
unsigned long ruint64
Unsigned 64-bit integer.
Definition rtypes.h:193
unsigned short ruint16
Unsigned 16-bit integer.
Definition rtypes.h:191
Atomic load / store / exchange / CAS / fetch-modify operations on integer, unsigned-integer and point...
Fixed-width bitset with bit / byte / word accessors and bitwise compound operations.
Refcount base struct shared by every refcounted type in rlib.
Foundational type aliases used by every rlib header.
Fixed-width bitset.
Definition rbitset.h:68
One-shot initialisation guard.
Definition rthreads.h:79
rauint state
Definition rthreads.h:80
rpointer ret
Definition rthreads.h:81
Thread-specific storage slot.
Definition rthreads.h:101
RDestroyNotify notify
Definition rthreads.h:102