These functions abstract threading related aspects. More...
Macros | |
#define | ruMutexTryLock(m) ruMutexTryLockLoc(m, __FILE__, __func__, __LINE__) |
#define | ruMutexLock(m) ruMutexLockLoc(m, __FILE__, __func__, __LINE__) |
#define | ruMutexUnlock(m) ruMutexUnlockLoc(m, __FILE__, __func__, __LINE__) |
#define | ruCounterInc(counter, value) ruCounterIncValue(counter, value, NULL) |
#define | ruCounterRead(counter) ruCounterIncValue(counter, 0, NULL) |
#define | ruCountSet(counter, value) ruCountSetValue(counter, value, NULL) |
Typedefs | |
typedef void * | ruTrace |
typedef unsigned long | ru_tid |
typedef pthread_t | ruThreadId |
typedef void * | ruThread |
typedef void * | ruCount |
typedef void *(* | ruStartFunc) (void *context) |
typedef void * | ruCond |
Opaque object abstracting condition signaling. More... | |
typedef void * | ruMutex |
Opaque object abstracting object locking. More... | |
Functions | |
RUAPI void | ruBacktraceInit (perm_chars exePath) |
Sets the path to the current executable. More... | |
RUAPI ruList | ruBacktrace (int32_t *code) |
Returns a list of ruTrace elements ordered so that the caller is last. More... | |
RUAPI void | ruTraceLog (trans_chars tag, int32_t skip) |
Logs a backtrace. More... | |
RUAPI perm_chars | ruTraceStr (ruTrace rt) |
Returns an optimized string representation of the given ruTrace object. More... | |
RUAPI perm_chars | ruTraceFilePath (ruTrace rt) |
Returns the full path to the filename of the given ruTrace object if set. More... | |
RUAPI perm_chars | ruTraceFileName (ruTrace rt) |
Returns the basename of the filename of the given ruTrace object if set. More... | |
RUAPI perm_chars | ruTraceFunc (ruTrace rt) |
Returns the function name of the given ruTrace object if set. More... | |
RUAPI uint32_t | ruTraceLine (ruTrace rt) |
Returns the line number of the given ruTrace object if set. More... | |
RUAPI perm_ptr | ruTraceOffset (ruTrace rt) |
Returns the offset from the given function of the given ruTrace object if set. More... | |
RUAPI perm_ptr | ruTraceAddr (ruTrace rt) |
Returns the instruction pointer of the given ruTrace object. More... | |
RUAPI ru_tid | ruThreadGetId (void) |
RUAPI void | ruThreadSetName (trans_chars name) |
RUAPI perm_chars | ruThreadGetName (void) |
RUAPI ruThread | ruThreadCreate (ruStartFunc start, alloc_chars name, void *usrCtx) |
RUAPI ruThread | ruThreadCreateBg (ruStartFunc start, alloc_chars name, void *usrCtx) |
Creates a new thread with background priority. More... | |
RUAPI bool | ruThreadFinished (ruThread tid, int32_t *code) |
Whether thraed has finished and is joinable. More... | |
RUAPI ruThreadId | ruThreadNativeId (ruThread tid, int32_t *code) |
Returns the thread id of the given ruThread. More... | |
RUAPI bool | ruThreadWait (ruThread tid, sec_t tosecs, void **exitVal) |
RUAPI int | ruThreadJoin (ruThread tid, void **exitVal) |
RUAPI int32_t | ruThreadKill (ruThread tid) |
RUAPI ruCond | ruCondInit (void) |
Initialize a new ruCond condition variable. More... | |
RUAPI ruCond | ruCondFree (ruCond c) |
Free up given ruCond object. More... | |
RUAPI void | ruCondSignal (ruCond c) |
Unblock a thread waiting for the given condition variable. More... | |
RUAPI void | ruCondWaitTil (ruCond c, ruMutex m, int32_t msTimeout) |
Wait on the given condition variable or the given timeout. More... | |
RUAPI void | ruCondWait (ruCond c, ruMutex m) |
Wait on the given condition variable. More... | |
RUAPI ruMutex | ruMutexInit (void) |
Initialize a new ruMutex. More... | |
RUAPI bool | ruMutexTryLockLoc (ruMutex m, trans_chars filePath, trans_chars func, int32_t line) |
Tries to aquire a lock for the given ruMutex without blocking. More... | |
RUAPI void | ruMutexLockLoc (ruMutex m, trans_chars filePath, trans_chars func, int32_t line) |
Aquire a lock for the given ruMutex blocking until it is given. More... | |
RUAPI void | ruMutexUnlockLoc (ruMutex m, trans_chars filePath, trans_chars func, int32_t line) |
Return the aquired mutex lock so other threads can use it. More... | |
RUAPI ruMutex | ruMutexFree (ruMutex m) |
Free up given ruMutex object. More... | |
RUAPI ruCount | ruCounterNew (int64_t initialCount) |
Returns a new thread safe counter initialized to given value. More... | |
RUAPI int64_t | ruCounterIncValue (ruCount counter, int64_t value, int32_t *code) |
Increments the counter by given value and returns the new value. More... | |
RUAPI int64_t | ruCountSetValue (ruCount counter, int64_t value, int32_t *code) |
Sets the counter to given value and returns the previous value. More... | |
RUAPI ruCount | ruCountFree (ruCount counter) |
Frees given counter. More... | |
These functions abstract threading related aspects.
#define ruCounterInc | ( | counter, | |
value | |||
) | ruCounterIncValue(counter, value, NULL) |
Calls ruCounterIncValue without the code parameter
#define ruCounterRead | ( | counter | ) | ruCounterIncValue(counter, 0, NULL) |
Calls ruCounterIncValue with 0 to simply return the current value
#define ruCountSet | ( | counter, | |
value | |||
) | ruCountSetValue(counter, value, NULL) |
Calls ruCountSetValue without the code parameter
#define ruMutexLock | ( | m | ) | ruMutexLockLoc(m, __FILE__, __func__, __LINE__) |
#define ruMutexTryLock | ( | m | ) | ruMutexTryLockLoc(m, __FILE__, __func__, __LINE__) |
#define ruMutexUnlock | ( | m | ) | ruMutexUnlockLoc(m, __FILE__, __func__, __LINE__) |
typedef unsigned long ru_tid |
Thread Id type
typedef void* ruCond |
Opaque object abstracting condition signaling.
typedef void* ruCount |
Thread Safe Counter
typedef void* ruMutex |
Opaque object abstracting object locking.
typedef void*(* ruStartFunc) (void *context) |
Signature of a thread starting function.
typedef void* ruThread |
Thread Identifier
typedef pthread_t ruThreadId |
Native thread identifier
typedef void* ruTrace |
Backtrace Element
RUAPI ruList ruBacktrace | ( | int32_t * | code | ) |
Returns a list of ruTrace elements ordered so that the caller is last.
code | (Optional) Stores RUE_OK on success or RUE_FEATURE_NOT_SUPPORTED when backtrace was not built in. |
RUAPI void ruBacktraceInit | ( | perm_chars | exePath | ) |
Sets the path to the current executable.
exePath | Optional for helping to find symbols. |
RUAPI ruCond ruCondInit | ( | void | ) |
Initialize a new ruCond condition variable.
RUAPI void ruCondSignal | ( | ruCond | c | ) |
Unblock a thread waiting for the given condition variable.
c | The condition variable to signal. |
Wait on the given condition variable.
This function blocks the current thread waiting on the given condition variable, unblocks the given mutex, and relocks it again.
c | The condition variable to wait on. |
m | The mutex to unblock and relock. |
Wait on the given condition variable or the given timeout.
This function blocks the current thread waiting on the given condition variable, unblocks the given mutex, and relocks it again.
c | The condition variable to wait on. |
m | The mutex to unblock and relock. |
msTimeout | Amount of millisecond to wait or 0 for infinitely |
RUAPI int64_t ruCounterIncValue | ( | ruCount | counter, |
int64_t | value, | ||
int32_t * | code | ||
) |
Increments the counter by given value and returns the new value.
counter | Counter in question |
value | value to increment counter by |
code | Optional where error code will be stored |
RUAPI ruCount ruCounterNew | ( | int64_t | initialCount | ) |
Returns a new thread safe counter initialized to given value.
initialCount | Value to set at start |
Frees given counter.
counter | Counter to free |
RUAPI int64_t ruCountSetValue | ( | ruCount | counter, |
int64_t | value, | ||
int32_t * | code | ||
) |
Sets the counter to given value and returns the previous value.
counter | Counter in question |
value | new value to set counter to |
code | Optional where error code will be stored |
RUAPI ruMutex ruMutexInit | ( | void | ) |
Initialize a new ruMutex.
RUAPI void ruMutexLockLoc | ( | ruMutex | m, |
trans_chars | filePath, | ||
trans_chars | func, | ||
int32_t | line | ||
) |
Aquire a lock for the given ruMutex blocking until it is given.
The mutex is not meant to be reentrant, and is not on Windows. Meaning a thread calling ruMutexLock recursively will deadlock on the second call.
m | The mutex to lock. |
filePath | source file |
func | function name |
line | line number |
RUAPI bool ruMutexTryLockLoc | ( | ruMutex | m, |
trans_chars | filePath, | ||
trans_chars | func, | ||
int32_t | line | ||
) |
Tries to aquire a lock for the given ruMutex without blocking.
m | The mutex to lock. |
filePath | source file |
func | function name |
line | line number |
RUAPI void ruMutexUnlockLoc | ( | ruMutex | m, |
trans_chars | filePath, | ||
trans_chars | func, | ||
int32_t | line | ||
) |
Return the aquired mutex lock so other threads can use it.
m | The mutex to unlock. |
filePath | source file |
func | function name |
line | line number |
RUAPI ruThread ruThreadCreate | ( | ruStartFunc | start, |
alloc_chars | name, | ||
void * | usrCtx | ||
) |
Creates a new thread
start | The start function |
name | The name of the thread must be alloced will be freed, or NULL |
usrCtx | The start function's argument. |
RUAPI ruThread ruThreadCreateBg | ( | ruStartFunc | start, |
alloc_chars | name, | ||
void * | usrCtx | ||
) |
Creates a new thread with background priority.
start | The start function |
name | The name of the thread must be alloced will be freed, or NULL |
usrCtx | The start function's argument. |
RUAPI bool ruThreadFinished | ( | ruThread | tid, |
int32_t * | code | ||
) |
Whether thraed has finished and is joinable.
tid | Thread id of thread to join. |
code | Optional where error code will be stored |
RUAPI ru_tid ruThreadGetId | ( | void | ) |
Returns the id of the running thread
RUAPI perm_chars ruThreadGetName | ( | void | ) |
Returns the current thread name or NULL
RUAPI int ruThreadJoin | ( | ruThread | tid, |
void ** | exitVal | ||
) |
Waits for given thread to terminate
tid | Thread id of thread to join. |
exitVal | Where the threads return value will be store if not NULL. |
RUAPI int32_t ruThreadKill | ( | ruThread | tid | ) |
Sends a kill signal to the specified thread.
NOTE: Currently not supported on Android
tid | Thread id to send kill signal to |
RUAPI ruThreadId ruThreadNativeId | ( | ruThread | tid, |
int32_t * | code | ||
) |
RUAPI void ruThreadSetName | ( | trans_chars | name | ) |
Sets or clear name of the running thread
name | New name to set or NULL to clear/free the exisiting name. |
Waits for given thread to terminate for tosecs seconds and kills it after that
NOTE: Killing is currently not supported on Android.
tid | Thread id of thread to join. |
tosecs | Number of seconds to wait before killing the thread. |
exitVal | Where the threads return value will be store if not NULL and thread wasn't killed. |
RUAPI perm_chars ruTraceFileName | ( | ruTrace | rt | ) |
RUAPI perm_chars ruTraceFilePath | ( | ruTrace | rt | ) |
RUAPI perm_chars ruTraceFunc | ( | ruTrace | rt | ) |
RUAPI uint32_t ruTraceLine | ( | ruTrace | rt | ) |
RUAPI void ruTraceLog | ( | trans_chars | tag, |
int32_t | skip | ||
) |
Logs a backtrace.
tag | Content to log in front of the trace values. |
skip | Number of frames to skip usually 2 to skip ruTraceLog and ruBacktrace. |
RUAPI perm_chars ruTraceStr | ( | ruTrace | rt | ) |