OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsCore.h
1
3#ifndef __CORE_H__
4#define __CORE_H__
5
6
9// Core task/callback manager
10#include "gsCommon.h"
11#include "../darray.h"
12
13#if defined(__cplusplus)
14extern "C"
15{
16#endif
17
18
21#define GSICORE_DYNAMIC_TASK_LIST
22#define GSICORE_MAXTASKS 40
23
24
27typedef enum
28{
29 GSCore_IN_USE,
30 GSCore_SHUTDOWN_PENDING,
31 GSCore_SHUTDOWN_COMPLETE
32} GSCoreValue;
33
34
37typedef enum
38{
39 GSTaskResult_None,
40 GSTaskResult_InProgress,
41 GSTaskResult_Canceled,
42 GSTaskResult_TimedOut,
43 GSTaskResult_Finished
44} GSTaskResult;
45
46
49// delegates (optional, may be NULL)
50typedef void(*GSTaskExecuteFunc) (void* theTaskData);
51typedef void(*GSTaskCallbackFunc)(void* theTaskData, GSTaskResult theResult);
52typedef void(*GSTaskCancelFunc) (void* theTaskData);
53typedef gsi_bool(*GSTaskCleanupFunc) (void* theTaskData); // post run cleanup
54typedef GSTaskResult(*GSTaskThinkFunc)(void* theTaskData);
55
56
59// "Private" struct for dispatching tasks. Once tasks have been put in the queue
60// they should only be modified from the think thread.
61// - When creating a task, you should set only the task data and delegates
62typedef struct
63{
64 int mId;
65 gsi_time mTimeout;
66 gsi_time mStartTime;
67 gsi_bool mAutoThink;
68
69 // These are not exclusive states (use bit flags?)
70 gsi_i32 mIsStarted;
71 gsi_i32 mIsRunning;
72 gsi_i32 mIsCanceled;
73 gsi_i32 mIsCallbackPending; // does the task require a callback?
74
75 // delegates
76 void* mTaskData;
77 GSTaskExecuteFunc mExecuteFunc;
78 GSTaskCallbackFunc mCallbackFunc;
79 GSTaskCancelFunc mCancelFunc;
80 GSTaskCleanupFunc mCleanupFunc;
81 GSTaskThinkFunc mThinkFunc;
82} GSTask;
83
84
87typedef struct
88{
89 gsi_u32 mRefCount;
90
91 gsi_bool volatile mIsStaticInitComplete; // once per application init
92 gsi_bool volatile mIsInitialized; // gsi_true when ready to use
93 gsi_bool volatile mIsShuttingDown; // gsi_true when shutting down
94
95 GSICriticalSection mQueueCrit;
96 #ifdef GSICORE_DYNAMIC_TASK_LIST
97 DArray mTaskArray;
98 #else
99 GSTask* mTaskArray[GSICORE_MAXTASKS];
100 #endif
101
102} GSCoreMgr;
103
104
107void gsCoreInitialize (void);
108void gsCoreThink (gsi_time theMS);
109void gsCoreShutdown (void);
110GSCoreValue gsCoreIsShutdown(void);
111
112GSTaskResult gsCoreTaskThink(GSTask* theTask);
113void gsiCoreExecuteTask (GSTask* theTask, gsi_time theTimeoutMs);
114void gsiCoreCancelTask (GSTask* theTask);
115
116GSTask* gsiCoreCreateTask(void);
117
118
121#if defined(__cplusplus)
122}
123#endif
124
125
128#endif // __CORE_H__
Definition gsCore.h:88
Definition gsCore.h:63