CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <cx/cx.h>
10#include <cx/platform/base.h>
11
12#include <cx/thread/threadobj.h>
13
24
30_Ret_opt_valid_ Thread* thrCurrent(void);
31
35intptr thrOSThreadID(_In_ Thread* thread);
36
42
43_Ret_opt_valid_ _Check_return_ Thread*
44_thrCreate(_In_ threadFunc func, _In_ strref name, int n, _In_ stvar args[], bool ui);
45// Thread* thrCreate(threadFunc func, strref name, ...)
46//
47// Creates and starts a thread. The return value MUST be released with thrRelease to avoid leaking
48// memory.
49#define thrCreate(func, name, ...) \
50 _thrCreate(func, name, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ }, false)
51#define thrCreateUI(func, name, ...) \
52 _thrCreate(func, name, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ }, true)
53
54void _thrRun(_In_ threadFunc func, _In_ strref name, int n, _In_ stvar args[]);
55
66#define thrRun(func, name, ...) \
67 _thrRun(func, name, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ })
68
72_meta_inline bool thrRunning(_In_ Thread* thread)
73{
74 return atomicLoad(bool, &thread->running, Acquire);
75}
76
96_meta_inline bool thrLoop(_In_ Thread* thread)
97{
98 return !atomicLoad(bool, &thread->requestExit, Acquire);
99}
100
111bool thrRequestExit(_In_ Thread* thread);
112
119bool thrWait(_In_ Thread* thread, int64 timeout);
120
127bool thrShutdown(_In_ Thread* thread);
128
136int thrShutdownMany(_In_ sa_Thread threads);
137
138bool _thrPlatformSetPriority(_Inout_ Thread* thread, int prio);
139
146#define thrSetPriority(thread, prio) _thrPlatformSetPriority(thread, THREAD_##prio)
147
154#define thrSetPriorityV(thread, prio) _thrPlatformSetPriority(thread, prio)
155
164#define thrRelease(pthread) objRelease(pthread)
165
166typedef struct Event Event;
167
177void thrRegisterSysThread(_Inout_ Thread* thread);
178
180// end of thread_core group
Compiler and platform detection macros.
#define stvar(typen, val)
Definition stvar.h:153
bool thrLoop(Thread *thread)
Definition thread.h:96
int thrShutdownMany(sa_Thread threads)
intptr thrOSThreadID(Thread *thread)
Thread * thrCurrent(void)
bool thrShutdown(Thread *thread)
bool thrRunning(Thread *thread)
Definition thread.h:72
intptr thrCurrentOSThreadID(void)
ThreadPriority
Thread scheduling priority levels.
Definition thread.h:15
void thrRegisterSysThread(Thread *thread)
bool thrRequestExit(Thread *thread)
bool thrWait(Thread *thread, int64 timeout)
@ THREAD_Normal
Normal priority (default)
Definition thread.h:16
@ THREAD_Idle
Idle priority (only runs when system is idle)
Definition thread.h:19
@ THREAD_High
High priority.
Definition thread.h:20
@ THREAD_Higher
Higher priority.
Definition thread.h:21
@ THREAD_Batch
Batch processing priority (below normal)
Definition thread.h:17
@ THREAD_Low
Low priority.
Definition thread.h:18
@ THREAD_Realtime
Real-time priority (use with caution)
Definition thread.h:22
Definition event.h:53