AcessNative - Fixing crashes
[tpg/acess2.git] / AcessNative / acesskernel_src / include / threads_int.h
1 #ifndef _THREADS_INT_H_
2 #define _THREADS_INT_H_
3
4 /**
5  * \brief IPC Message
6  */
7 typedef struct sMessage
8 {
9         struct sMessage *Next;  //!< Next message in thread's inbox
10         tTID    Source; //!< Source thread ID
11         Uint    Length; //!< Length of message data in bytes
12         Uint8   Data[]; //!< Message data
13 } tMsg;
14
15 typedef struct sProcess
16 {
17          int    nThreads;
18          int    NativePID;
19         char    *CWD;
20         char    *Chroot;
21          int    MaxFD;
22 } tProcess;
23
24 struct sThread
25 {
26         struct sThread  *GlobalNext;
27         struct sThread  *Next;
28
29          int    KernelTID;
30
31         tTID    TID, PID;
32         tUID    UID, GID;
33
34         struct sThread  *Parent;
35
36         char    *ThreadName;
37
38          int    Status; // 0: Dead, 1: Active, 2: Paused, 3: Asleep
39          int    ExitStatus;
40          int    _errno;
41
42         // Threads waiting for this thread to exit.
43         // Quit logic:
44         // - Wait for `WaitingThreads` to be non-null (maybe?)
45         // - Wake first in the queue, wait for it to be removed
46         // - Repeat
47         // - Free thread and quit kernel thread
48         struct sThread  *WaitingThreads;
49         struct sThread  *WaitingThreadsEnd;
50
51         tProcess        *Process;       
52
53         Uint32  Events, WaitMask;
54         void    *EventSem;      // Should be SDL_sem, but I don't want SDL in this header
55
56         // Message queue
57         tMsg * volatile Messages;       //!< Message Queue
58         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
59 };
60
61 enum {
62         THREAD_STAT_NULL,       // Invalid process
63         THREAD_STAT_ACTIVE,     // Running and schedulable process
64         THREAD_STAT_SLEEPING,   // Message Sleep
65         THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
66         THREAD_STAT_SEMAPHORESLEEP,     // Semaphore Sleep
67         THREAD_STAT_QUEUESLEEP, // Queue
68         THREAD_STAT_EVENTSLEEP, // Event sleep
69         THREAD_STAT_WAITING,    // ??? (Waiting for a thread)
70         THREAD_STAT_PREINIT,    // Being created
71         THREAD_STAT_ZOMBIE,     // Died/Killed, but parent not informed
72         THREAD_STAT_DEAD,       // Awaiting burial (free)
73         THREAD_STAT_BURIED      // If it's still on the list here, something's wrong
74 };
75 extern tThread  *Threads_GetThread(Uint TID);
76
77 #endif
78

UCC git Repository :: git.ucc.asn.au