regify utility 2.1.0-0
 
Loading...
Searching...
No Matches
thread.h
1/*
2 * Copyright regify
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#ifndef REGIFY_UTIL_THREAD_H
24#define REGIFY_UTIL_THREAD_H
25
26#ifdef RUMS
27#define RU_THREAD_LOCAL __declspec(thread)
28#else
29#include <pthread.h>
30#ifdef DO_IOS
31#define RU_THREAD_LOCAL thread_local
32#else
33#define RU_THREAD_LOCAL __thread
34#endif
35#endif
36
46typedef void* ruTrace;
47
52RUAPI void ruBacktraceInit(perm_chars exePath);
53
60RUAPI ruList ruBacktrace(int32_t* code);
61
68RUAPI void ruTraceLog(trans_chars tag, int32_t skip);
69
76
83
90
97
103RUAPI uint32_t ruTraceLine(ruTrace rt);
104
111
118
122typedef unsigned long ru_tid;
123
127#ifdef _WIN32
128typedef HANDLE ruThreadId;
129#else
130typedef pthread_t ruThreadId;
131#endif
132
136typedef void* ruThread;
137
141typedef void* ruCount;
142
146typedef void* (*ruStartFunc) (void* context);
147
148
154
160
166
174RUAPI ruThread ruThreadCreate(ruStartFunc start, alloc_chars name, void* usrCtx);
175
183RUAPI ruThread ruThreadCreateBg(ruStartFunc start, alloc_chars name, void* usrCtx);
184
191RUAPI bool ruThreadFinished(ruThread tid, int32_t* code);
192
199RUAPI ruThreadId ruThreadNativeId(ruThread tid, int32_t* code);
200
216RUAPI bool ruThreadWait(ruThread tid, sec_t tosecs, void** exitVal);
217
224RUAPI int ruThreadJoin(ruThread tid, void** exitVal );
225
239RUAPI int32_t ruThreadKill(ruThread tid);
240
244typedef void* ruCond;
245
249typedef void* ruMutex;
250
256RUAPI ruCond ruCondInit(void);
257
264
269RUAPI void ruCondSignal(ruCond c);
270
280RUAPI void ruCondWaitTil(ruCond c, ruMutex m, int32_t msTimeout);
281
290RUAPI void ruCondWait(ruCond c, ruMutex m);
291
297
307 int32_t line);
308
309#define ruMutexTryLock(m) ruMutexTryLockLoc(m, __FILE__, __func__, __LINE__)
310
321RUAPI void ruMutexLockLoc(ruMutex m, trans_chars filePath, trans_chars func,
322 int32_t line);
323
324#define ruMutexLock(m) ruMutexLockLoc(m, __FILE__, __func__, __LINE__)
325
333RUAPI void ruMutexUnlockLoc(ruMutex m, trans_chars filePath, trans_chars func,
334 int32_t line);
335
336#define ruMutexUnlock(m) ruMutexUnlockLoc(m, __FILE__, __func__, __LINE__)
337
344
350RUAPI ruCount ruCounterNew(int64_t initialCount);
351
359RUAPI int64_t ruCounterIncValue(ruCount counter, int64_t value, int32_t* code);
360
364#define ruCounterInc(counter, value) ruCounterIncValue(counter, value, NULL)
365
369#define ruCounterRead(counter) ruCounterIncValue(counter, 0, NULL)
370
378RUAPI int64_t ruCountSetValue(ruCount counter, int64_t value, int32_t* code);
379
383#define ruCountSet(counter, value) ruCountSetValue(counter, value, NULL)
384
391
396#endif //REGIFY_UTIL_THREAD_H
void * ruList
Opaque pointer to list object. See List Collection.
Definition list.h:103
const void * perm_ptr
A permanent pointer.
Definition regify-util.h:277
const char * trans_chars
A transient NULL terminated string pointer.
Definition regify-util.h:186
const char * perm_chars
A permanent NULL terminated string pointer.
Definition regify-util.h:176
long sec_t
A signed type for expressing seconds.
Definition regify-util.h:312
char * alloc_chars
An allocated NULL terminated string pointer.
Definition regify-util.h:199
RUAPI void ruCondSignal(ruCond c)
Unblock a thread waiting for the given condition variable.
void * ruTrace
Definition thread.h:46
RUAPI ruCond ruCondFree(ruCond c)
Free up given ruCond object.
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.
RUAPI bool ruThreadFinished(ruThread tid, int32_t *code)
Whether thraed has finished and is joinable.
RUAPI ruCount ruCountFree(ruCount counter)
Frees given counter.
RUAPI ruThread ruThreadCreate(ruStartFunc start, alloc_chars name, void *usrCtx)
RUAPI void ruBacktraceInit(perm_chars exePath)
Sets the path to the current executable.
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.
RUAPI ruCond ruCondInit(void)
Initialize a new ruCond condition variable.
RUAPI int64_t ruCountSetValue(ruCount counter, int64_t value, int32_t *code)
Sets the counter to given value and returns the previous value.
RUAPI perm_ptr ruTraceAddr(ruTrace rt)
Returns the instruction pointer of the given ruTrace object.
RUAPI perm_ptr ruTraceOffset(ruTrace rt)
Returns the offset from the given function of the given ruTrace object if set.
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.
RUAPI ruThreadId ruThreadNativeId(ruThread tid, int32_t *code)
Returns the thread id of the given ruThread.
RUAPI ru_tid ruThreadGetId(void)
void * ruCond
Opaque object abstracting condition signaling.
Definition thread.h:244
RUAPI uint32_t ruTraceLine(ruTrace rt)
Returns the line number of the given ruTrace object if set.
RUAPI int32_t ruThreadKill(ruThread tid)
RUAPI ruList ruBacktrace(int32_t *code)
Returns a list of ruTrace elements ordered so that the caller is last.
void * ruCount
Definition thread.h:141
RUAPI void ruCondWaitTil(ruCond c, ruMutex m, int32_t msTimeout)
Wait on the given condition variable or the given timeout.
RUAPI void ruThreadSetName(trans_chars name)
void * ruMutex
Opaque object abstracting object locking.
Definition thread.h:249
RUAPI void ruCondWait(ruCond c, ruMutex m)
Wait on the given condition variable.
void *(* ruStartFunc)(void *context)
Definition thread.h:146
RUAPI perm_chars ruTraceFileName(ruTrace rt)
Returns the basename of the filename of the given ruTrace object if set.
RUAPI perm_chars ruThreadGetName(void)
RUAPI bool ruThreadWait(ruThread tid, sec_t tosecs, void **exitVal)
RUAPI void ruTraceLog(trans_chars tag, int32_t skip)
Logs a backtrace.
RUAPI perm_chars ruTraceStr(ruTrace rt)
Returns an optimized string representation of the given ruTrace object.
void * ruThread
Definition thread.h:136
RUAPI ruMutex ruMutexInit(void)
Initialize a new ruMutex.
pthread_t ruThreadId
Definition thread.h:130
RUAPI int ruThreadJoin(ruThread tid, void **exitVal)
unsigned long ru_tid
Definition thread.h:122
RUAPI int64_t ruCounterIncValue(ruCount counter, int64_t value, int32_t *code)
Increments the counter by given value and returns the new value.
RUAPI perm_chars ruTraceFunc(ruTrace rt)
Returns the function name of the given ruTrace object if set.
RUAPI ruThread ruThreadCreateBg(ruStartFunc start, alloc_chars name, void *usrCtx)
Creates a new thread with background priority.
RUAPI perm_chars ruTraceFilePath(ruTrace rt)
Returns the full path to the filename of the given ruTrace object if set.
RUAPI ruMutex ruMutexFree(ruMutex m)
Free up given ruMutex object.
RUAPI ruCount ruCounterNew(int64_t initialCount)
Returns a new thread safe counter initialized to given value.