Modules/UDI - (minor) tiny fiddle to udic planning
[tpg/acess2.git] / AcessNative / acesskernel_src / include / threads_int.h
1 #ifndef _THREADS_INT_H_
2 #define _THREADS_INT_H_
3
4 #include <threads.h>
5
6 enum eThreadStatus {
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
20 };
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
35 };
36
37 /**
38  * \brief IPC Message
39  */
40 typedef struct sMessage
41 {
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
46 } tMsg;
47
48 typedef struct sProcess
49 {
50         tTID    PID;
51          int    nThreads;
52          int    NativePID;
53         char    *CWD;
54         char    *Chroot;
55          int    MaxFD;
56
57         tUID    UID, GID;
58 } tProcess;
59
60 struct sThread
61 {
62         struct sThread  *GlobalNext;
63         struct sThread  *Next;
64
65          int    KernelTID;
66         tProcess        *Process;       
67
68         tTID    TID;
69
70         struct sThread  *Parent;
71         char    *ThreadName;
72          int    bInstrTrace;
73
74         enum eThreadStatus      Status; // 0: Dead, 1: Active, 2: Paused, 3: Asleep
75          int    RetStatus;
76          int    _errno;
77
78         // Threads waiting for this thread to exit.
79         // Quit logic:
80         // - Wait for `WaitingThreads` to be non-null (maybe?)
81         // - Wake first in the queue, wait for it to be removed
82         // - Repeat
83         // - Free thread and quit kernel thread
84         struct sThread  *WaitingThreads;
85         struct sThread  *WaitingThreadsEnd;
86
87
88         tShortSpinlock  IsLocked;
89
90         void    *WaitPointer;
91
92         Uint32  EventState, WaitMask;
93         void    *EventSem;      // Should be SDL_sem, but I don't want SDL in this header
94
95         void    *ClientPtr;
96
97         // Message queue
98         tMsg * volatile Messages;       //!< Message Queue
99         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
100 };
101
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);
106
107 #endif
108

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