1 #ifndef _THREADS_INT_H_
2 #define _THREADS_INT_H_
7 THREAD_STAT_NULL, // Invalid process
8 THREAD_STAT_ACTIVE, // Running and schedulable process
9 THREAD_STAT_SLEEPING, // Message Sleep
10 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
11 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
12 THREAD_STAT_QUEUESLEEP, // Queue
13 THREAD_STAT_EVENTSLEEP, // Event sleep
14 THREAD_STAT_RWLOCKSLEEP,
15 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
16 THREAD_STAT_PREINIT, // Being created
17 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
18 THREAD_STAT_DEAD, // Awaiting burial (free)
19 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
21 static const char * const casTHREAD_STAT[] = {
22 "THREAD_STAT_NULL", // Invalid process
23 "THREAD_STAT_ACTIVE", // Running and schedulable process
24 "THREAD_STAT_SLEEPING", // Message Sleep
25 "THREAD_STAT_MUTEXSLEEP", // Mutex Sleep
26 "THREAD_STAT_SEMAPHORESLEEP", // Semaphore Sleep
27 "THREAD_STAT_QUEUESLEEP", // Queue
28 "THREAD_STAT_EVENTSLEEP", // Event sleep
29 "THREAD_STAT_RWLOCKSLEEP",
30 "THREAD_STAT_WAITING", // ??? (Waiting for a thread)
31 "THREAD_STAT_PREINIT", // Being created
32 "THREAD_STAT_ZOMBIE", // Died/Killed, but parent not informed
33 "THREAD_STAT_DEAD", // Awaiting burial (free)
34 "THREAD_STAT_BURIED" // If it's still on the list here, something's wrong
40 typedef struct sMessage
42 struct sMessage *Next; //!< Next message in thread's inbox
43 tTID Source; //!< Source thread ID
44 Uint Length; //!< Length of message data in bytes
45 Uint8 Data[]; //!< Message data
48 typedef struct sProcess
62 struct sThread *GlobalNext;
70 struct sThread *Parent;
74 enum eThreadStatus Status; // 0: Dead, 1: Active, 2: Paused, 3: Asleep
78 // Threads waiting for this thread to exit.
80 // - Wait for `WaitingThreads` to be non-null (maybe?)
81 // - Wake first in the queue, wait for it to be removed
83 // - Free thread and quit kernel thread
84 struct sThread *WaitingThreads;
85 struct sThread *WaitingThreadsEnd;
88 tShortSpinlock IsLocked;
92 Uint32 EventState, WaitMask;
93 void *EventSem; // Should be SDL_sem, but I don't want SDL in this header
98 tMsg * volatile Messages; //!< Message Queue
99 tMsg *LastMessage; //!< Last Message (speeds up insertion)
102 extern struct sThread *Threads_GetThread(Uint TID);
103 extern void Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
104 extern int Threads_int_Sleep(enum eThreadStatus Status, void *Ptr, int Num, tThread **ListHead, tThread **ListTail, tShortSpinlock *Lock);
105 extern void Threads_AddActive(tThread *Thread);