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 * \deprecated Deprecated in favor of GblThread. Soon to be removed.
7 *
8 * \author Falco Girgis
9 */
10#ifndef GIMBAL_THD_H
11#define GIMBAL_THD_H
12
13#include <gimbal/core/gimbal_typedefs.h>
15
16#define GBL_SELF_TYPE GblThd
17
19
20//! Deprecated legacy structure for thread-local storage and context
21typedef struct GblThd {
22 GblCallRecord callRecord;
23 const char* pName;
24 uint32_t logStackDepth;
25 GblContext* pContext;
26 GblStackFrame* pStackFrameTop;
27 GblBool initialized;
28} GblThd;
29
30// ===== Public API =====
31GBL_EXPORT GblThd* GblThd_current (void) GBL_NOEXCEPT;
32GBL_EXPORT GblContext* GblThd_context (GBL_CSELF) GBL_NOEXCEPT;
33
34GBL_EXPORT const char* GblThd_name (GBL_CSELF) GBL_NOEXCEPT;
35GBL_EXPORT GBL_RESULT GblThd_setName (GBL_SELF, const char* pName) GBL_NOEXCEPT;
36
37GBL_INLINE GblCallRecord* GblThd_callRecord (GBL_SELF) GBL_NOEXCEPT;
38GBL_EXPORT GBL_RESULT GblThd_setCallRecord (GBL_SELF, const GblCallRecord* pRecord) GBL_NOEXCEPT;
39
40GBL_INLINE GblStackFrame* GblThd_stackFrameTop (GBL_CSELF) GBL_NOEXCEPT;
41GBL_INLINE GBL_RESULT GblThd_stackFramePush (GBL_SELF, GblStackFrame* pFrame) GBL_NOEXCEPT;
42GBL_INLINE GBL_RESULT GblThd_stackFramePop (GBL_SELF) GBL_NOEXCEPT;
43
44GBL_EXPORT GBL_RESULT GblThd_logPush (GBL_SELF) GBL_NOEXCEPT;
45GBL_EXPORT GBL_RESULT GblThd_logPop (GBL_SELF, uint32_t count) GBL_NOEXCEPT;
46
47// ===== Implementation =====
48///\cond
49
50GBL_EXPORT GblContext* GblContext_global(void) GBL_NOEXCEPT;
51///\endcond
52
53GBL_INLINE GblStackFrame* GblThd_stackFrameTop(const GblThd* pThread) GBL_NOEXCEPT {
54 if(!pThread) pThread = GblThd_current();
55 return pThread->pStackFrameTop;
56}
57
58GBL_INLINE GBL_RESULT GblThd_stackFramePush(GblThd* pThread, GblStackFrame* pFrame) GBL_NOEXCEPT {
59 if(!pThread) pThread = GblThd_current();
60 if(pFrame) {
61 pFrame->pPrevFrame = pThread->pStackFrameTop;
62 if(GBL_RESULT_ERROR(pThread->callRecord.result)) {
63 GblThd_setCallRecord(pThread, GBL_NULL);
64 }
65 }
66 pThread->pStackFrameTop = pFrame;
67 return GBL_RESULT_SUCCESS;
68}
69
70GBL_INLINE GBL_RESULT GblThd_stackFramePop(GblThd* pThread) GBL_NOEXCEPT {
71 if(!pThread) pThread = GblThd_current();
72 GBL_ASSERT(pThread->pStackFrameTop);
73 GblStackFrame* pPrevFrame = pThread->pStackFrameTop;
74 pThread->pStackFrameTop = pThread->pStackFrameTop? pThread->pStackFrameTop->pPrevFrame : GBL_NULL;
75 pPrevFrame->pPrevFrame = GBL_NULL;
76 return GBL_RESULT_SUCCESS;
77}
78
79GBL_INLINE GblCallRecord* GblThd_callRecord(GblThd* pThread) GBL_NOEXCEPT {
80 if(!pThread) {
81 pThread = GblThd_current();
82 }
83 return &pThread->callRecord;
84}
85
87
88#undef GBL_SELF_TYPE
89
90#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)
Deprecated legacy structure for thread-local storage and context.
Definition gimbal_thd.h:21