2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef GIMBAL_THREAD_H
22#define GIMBAL_THREAD_H
24#include "../meta/instances/gimbal_object.h"
25#include "../meta/signals/gimbal_signal.h"
28#include "../allocators/gimbal_scope_allocator.h"
32
33
34
36#define GBL_THREAD(self) (GBL_CAST(GblThread, self))
38#define GBL_THREAD_GET_CLASS(self) (GBL_CLASSOF(GblThread, self))
41#define GBL_SELF_TYPE GblThread
72
73
74
75
76
77
78
79
80
81
90
91
92
93
94
95
96
97
98
119 (started, (GBL_INSTANCE_TYPE, pReceiver)),
120 (finished, (GBL_INSTANCE_TYPE, pReceiver), (GBL_ENUM_TYPE, result)),
121 (signaled, (GBL_INSTANCE_TYPE, pReceiver), (GBL_ENUM_TYPE, signal))
126
127
128
141
142
143
144
183
184
185
186
196 const char* pMessage,
203
204
205
219#define GblThread_create__3(cb, ud, start) ((GblThread_create)(cb, ud, start))
220#define GblThread_create__2(cb, ud) (GblThread_create__3
(cb, ud, GBL_TRUE))
221#define GblThread_create__1(cb) (GblThread_create__2
(cb, GBL_NULL))
223#define GblThread_exit__2(result, msg)
225#define GblThread_exit__1(result)
228#define GblThread_nanoSleep__2(nsec, pRem)
230#define GblThread_nanoSleep__1(nsec)
231 (GblThread_nanoSleep__2
(nsec, GBL_NULL))
233#define GblThread_foreach__2(it, closure)
235#define GblThread_foreach__1(it)
236 (GblThread_foreach__2
(it, GBL_NULL))
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLOSURE_TYPE
Type UUID for GblClosure.
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_DECLARE_ENUM(E)
#define GBL_CLASS_DERIVE(...)
#define GBL_ENUM_TYPE
Type UUID of GblEnumClass.
#define GBL_FLAGS_TYPE
GblType UUID for flags.
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
#define GBL_FUNCTION_TYPE
#define GBL_BOOL_TYPE
Builtin ID for boolean GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
#define GBL_SIGNALS(instanceStruct,...)
@ GBL_THREAD_PRIORITY_MEDIUM
Medium.
@ GBL_THREAD_PRIORITY_LOW
Lowest.
@ GBL_THREAD_PRIORITY_HIGH
High.
@ GBL_THREAD_PRIORITY_REAL_TIME
Highest.
@ GBL_THREAD_STATE_RUNNING
Running/Executing.
@ GBL_THREAD_STATE_FINISHED
Finished/Completed.
@ GBL_THREAD_STATE_INITIALIZING
Initializing/Constructing.
@ GBL_THREAD_STATE_UNKNOWN
Unknown.
@ GBL_THREAD_STATE_READY
Ready/Waiting.
#define GblThread_nanoSleep(...)
#define GblThread_exit(...)
GblThread * GblThread_find(const char *pName)
Searches (linearly) for a thread with the string name given by pName.
#define GblThread_create(...)
#define GblThread_foreach(...)
GblType GblThread_type(void)
Returns the GblType UUID associated with GblThread.
size_t GblThread_count(void)
Returns the current number of live threads (not necessarily all active)
uintptr_t GblThreadAffinity
Represents a CPU affinity bitmask, with each bit being affinity to a single core.
GblBool GblThread_foreach(GblThreadIterFn pIt, void *pCl)
Iterates over all live threads, passing each thread and pCl back to the pIt callback.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
Captures a result, its stringified message, and a source context.
GblThreadFn pFnRun
Main execution entry point for a given thread, calls callback + closure then signals.
Object representing a thread, its local storage, and logic.
#define GblThread_nanoSleep(...)
Sleeps the current thread for nsec nanoseconds, returning the remaining time optionally within pRemai...
GBL_RESULT GblThread_setPriority(GblThread *pSelf, GBL_THREAD_PRIORITY priority)
Sets the priority of the given thread to priority.
GBL_RESULT GblThread_setAffinity(GblThread *pSelf, GblThreadAffinity affinity)
Sets the CPU affinity of the given thread to affinity.
GBL_RESULT GblThread_join(GblThread *pSelf)
Blocks execution of the current thread, awaiting the completion of the given thread.
#define GblThread_exit(...)
Ends execution of the currently executing thread, returning result and storing the given source conte...
GblThread * GblThread_ref(const GblThread *pSelf)
Returns a new reference to an existing thread, incrementing its reference count by 1.
GBL_RESULT GblThread_spinWait(GblThread *pSelf)
Performs a non-blocking wait on the given thread, spinning on a timeout.
const char * GblThread_name(const GblThread *pSelf)
Returns the string name assigned to the given thread.
GBL_RESULT GblThread_yield(void)
Suspends execution of the current thread, allowing other threads to execute temporarily.
#define GblThread_create(...)
Creates a GblThread instance with the given callback and userdata and optionally starts its execution...
GblThreadFn GblThread_callback(const GblThread *pSelf)
Returns the C callback function assigned to the given thread, or NULL if there isn't one.
void GblThread_setCallback(GblThread *pSelf, GblThreadFn pCb)
Assigns the C callback function of the given thread to pCb, which will be executed with the thread.
GBL_RESULT GblThread_setName(GblThread *pSelf, const char *pName)
Sets the string name pName to be the name of the given thread.
GBL_RESULT GblThread_start(GblThread *pSelf)
Immediately starts a thread which has not yet joined or finished executing.
volatile sig_atomic_t signalStatus
Pending signal state for a given thread.
GBL_THREAD_STATE state
Current state for a given thread MAKE ME ATOMIC.
GblBool GblThread_isJoined(const GblThread *pSelf)
Returns GBL_TRUE if the given thread has been joined with its parent and is done executing,...
void GblThread_setClosure(GblThread *pSelf, GblClosure *pClosure)
Assigns the closure of the given thread to pClosure, freeing the previous closure if there was one.
GblRefCount GblThread_unref(GblThread *pSelf)
Decrements the reference count of a GblThread instance, deleting it if it's the last one.
GblCallRecord returnStatus
Return information from a completed thread.
GblThread * GblThread_current(void)
Returns a pointer to the GblThread instance associatedw with the current thread.
GblClosure * GblThread_closure(const GblThread *pSelf)
Returns the closure assigned to the given thread, or NULL if there isn't one.