libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_thd.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblThd, legacy, deprecated thread API
3 * \ingroup core
4 * \deprecated Use gimbal_thread.h
5 *
6 * \todo
7 * - get rid of me
8 *
9 * \author Falco Girgis
10 */
11#ifndef GIMBAL_THD_H
12#define GIMBAL_THD_H
13
14#include <gimbal/core/gimbal_typedefs.h>
16
17#define GBL_SELF_TYPE GblThd
18
20
21//! Deprecated legacy structure for thread-local storage and context
22typedef struct GblThd {
23 GblCallRecord callRecord;
24 const char* pName;
25 uint32_t logStackDepth;
26 GblContext* pContext;
27 GblStackFrame* pStackFrameTop;
28 GblBool initialized;
29} GblThd;
30
31// ===== Public API =====
32GBL_EXPORT GblThd* GblThd_current (void) GBL_NOEXCEPT;
33GBL_EXPORT GblContext* GblThd_context (GBL_CSELF) GBL_NOEXCEPT;
34
35GBL_EXPORT const char* GblThd_name (GBL_CSELF) GBL_NOEXCEPT;
36GBL_EXPORT GBL_RESULT GblThd_setName (GBL_SELF, const char* pName) GBL_NOEXCEPT;
37
39GBL_EXPORT GBL_RESULT GblThd_setCallRecord (GBL_SELF, const GblCallRecord* pRecord) GBL_NOEXCEPT;
40
41GBL_INLINE GblStackFrame* GblThd_stackFrameTop (GBL_CSELF) GBL_NOEXCEPT;
42GBL_INLINE GBL_RESULT GblThd_stackFramePush (GBL_SELF, GblStackFrame* pFrame) GBL_NOEXCEPT;
43GBL_INLINE GBL_RESULT GblThd_stackFramePop (GBL_SELF) GBL_NOEXCEPT;
44
45GBL_EXPORT GBL_RESULT GblThd_logPush (GBL_SELF) GBL_NOEXCEPT;
46GBL_EXPORT GBL_RESULT GblThd_logPop (GBL_SELF, uint32_t count) GBL_NOEXCEPT;
47
48// ===== Implementation =====
49///\cond
50
51GBL_EXPORT GblContext* GblContext_global(void) GBL_NOEXCEPT;
52///\endcond
53
54GBL_INLINE GblStackFrame* GblThd_stackFrameTop(const GblThd* pThread) GBL_NOEXCEPT {
55 if(!pThread) pThread = GblThd_current();
56 return pThread->pStackFrameTop;
57}
58
59GBL_INLINE GBL_RESULT GblThd_stackFramePush(GblThd* pThread, GblStackFrame* pFrame) GBL_NOEXCEPT {
60 if(!pThread) pThread = GblThd_current();
61 if(pFrame) {
62 pFrame->pPrevFrame = pThread->pStackFrameTop;
63 if(GBL_RESULT_ERROR(pThread->callRecord.result)) {
64 GblThd_setCallRecord(pThread, GBL_NULL);
65 }
66 }
67 pThread->pStackFrameTop = pFrame;
68 return GBL_RESULT_SUCCESS;
69}
70
71GBL_INLINE GBL_RESULT GblThd_stackFramePop(GblThd* pThread) GBL_NOEXCEPT {
72 if(!pThread) pThread = GblThd_current();
73 GBL_ASSERT(pThread->pStackFrameTop);
74 GblStackFrame* pPrevFrame = pThread->pStackFrameTop;
75 pThread->pStackFrameTop = pThread->pStackFrameTop? pThread->pStackFrameTop->pPrevFrame : GBL_NULL;
76 pPrevFrame->pPrevFrame = GBL_NULL;
77 return GBL_RESULT_SUCCESS;
78}
79
80GBL_INLINE GblCallRecord* GblThd_callRecord(GblThd* pThread) GBL_NOEXCEPT {
81 if(!pThread) {
82 pThread = GblThd_current();
83 }
84 return &pThread->callRecord;
85}
86
88
89#undef GBL_SELF_TYPE
90
91#endif // GIMBAL_THD_H
#define GBL_NULL
#define GBL_NOEXCEPT
#define GBL_INLINE
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_ASSERT(...)
#define GBL_RESULT_ERROR(value)
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
Captures a result, its stringified message, and a source context.
Represents a single function's stack frame, from GBL_CTX_BEGIN() to GBL_CTX_END()
Deprecated legacy structure for thread-local storage and context.
Definition gimbal_thd.h:22