libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_main_loop.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblMainLoop task scheduler priority queue
3 * \ingroup core
4 * \todo
5 * - implement me
6 *
7 * \author 2023 Falco Girgis
8 * \copyright MIT License
9 */
10
11#ifndef GIMBAL_MAIN_LOOP_H
12#define GIMBAL_MAIN_LOOP_H
13
14#include "../meta/instances/gimbal_object.h"
15#include "../meta/signals/gimbal_signal.h"
16#include "../containers/gimbal_linked_list.h"
17
18#define GBL_SELF_TYPE GblMainLoop
19
21
24
25//! Enumeration for
26typedef enum GBL_PRIORITY_LEVEL {
27 GBL_PRIORITY_IDLE,
28 GBL_PRIORITY_HIGH_IDLE,
29 GBL_PRIORITY_LOW,
30 GBL_PRIORITY_DEFAULT,
31 GBL_PRIORITY_HIGH,
32 GBL_PRIORITY_COUNT
33} GBL_PRIORITY_LEVEL;
34
35/*! \struct GblMainLoopClass
36 * \extends GblObjectClass
37 * \brief GblClass VTable structure for GblMainLoop
38 *
39 * WIP
40 *
41 * \sa GblMainLoop
42 */
43GBL_CLASS_DERIVE(GblMainLoop, GblObject)
44 GBL_RESULT (*pFnEnqueueTask)(GBL_SELF, GblTask* pTask);
45 GBL_RESULT (*pFnExecTask) (GBL_SELF, GblTask* pTask);
46 GBL_RESULT (*pFnCancelTask) (GBL_SELF, GblTask* pTask);
47 GBL_RESULT (*pFnExecIdle) (GBL_SELF);
49
50// Needs a context with queue
51/*! \struct GblMainLoop
52 * \extends GblObject
53 * \brief Sequentially executing priority queue of GblTask objects
54 *
55 * WIP
56 *
57 * \sa GblMainLoopClass
58 */
60 union {
61 GblTask* pHead;
62 GblLinkedListNode listNode;
63 } taskQueue[GBL_PRIORITY_COUNT];
64 size_t taskCount;
65 uint32_t taskBitMap;
66 GblTask* pActiveTask;
67 GBL_PRIORITY_LEVEL prevTaskPriority;
69
70GBL_SIGNALS(GblMainLoop,
71 (execIdle, GBL_INSTANCE_TYPE),
72 (taskEnqueued, GBL_INSTANCE_TYPE, GBL_INSTANCE_TYPE)
73)
74
75GBL_EXPORT GblType GblMainLoop_type (void) GBL_NOEXCEPT;
76
77GBL_EXPORT GBL_RESULT GblMainLoop_enqueue (GBL_SELF, GblTask* pTask) GBL_NOEXCEPT;
78GBL_EXPORT GBL_RESULT GblMainLoop_cancel (GBL_SELF, GblTask* pTask) GBL_NOEXCEPT;
79GBL_EXPORT GblTask* GblMainLoop_top (GBL_CSELF) GBL_NOEXCEPT;
80GBL_EXPORT size_t GblMainLoop_depth (GBL_CSELF) GBL_NOEXCEPT;
81
82GBL_EXPORT GBL_RESULT GblMainLoop_iteration (GBL_SELF) GBL_NOEXCEPT;
83GBL_EXPORT GBL_RESULT GblMainLoop_exec (GBL_SELF) GBL_NOEXCEPT;
84GBL_EXPORT GBL_RESULT GblMainLoop_stop (GBL_SELF) GBL_NOEXCEPT;
85GBL_EXPORT GblBool GblMainLoop_isRunning (GBL_CSELF) GBL_NOEXCEPT;
86
88
89#undef GBL_SELF_TYPE
90
91#endif // GIMBAL_MAIN_LOOP_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_CLASS_DERIVE(...)
#define GBL_INSTANCE_END
#define GBL_EXPORT
#define GBL_CLASS_END
GBL_PRIORITY_LEVEL
Enumeration for.
#define GBL_SIGNALS(instanceStruct,...)
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
Sequentially executing priority queue of GblTask objects.