Nativelib - Fix clang compilation issues
[tpg/acess2.git] / Tools / nativelib / include / threads_int.h
1 /*
2  * Acess2 libnative (Kernel Simulation Library)
3  * - By John Hodge (thePowersGang)
4  *
5  * threads_int.h
6  * - Threads handling definitions
7  */
8 #ifndef _THREADS_INT_H_
9 #define _THREADS_INT_H_
10
11 #include <shortlock.h>
12
13 #ifndef _THREADS_H_
14 typedef struct sThread  tThread;
15 #endif
16
17 #define THREAD_EVENT_RWLOCK     (1 << 8)
18
19 typedef struct sThreadIntMutex  tThreadIntMutex;        // actually pthreads
20 typedef struct sThreadIntSem    tThreadIntSem;
21
22 struct sProcess
23 {
24         struct sProcess *Next;
25         struct sThread  *Threads;
26
27          int    PID;
28          int    UID, GID;
29         
30         char    *CWD;
31         char    *Chroot;
32
33          int    MaxFDs;
34         void    *Handles;
35 };
36
37 struct sThread
38 {
39         struct sThread  *Next;
40         struct sThread  *ListNext;
41
42         struct sProcess *Process;
43         struct sThread  *ProcNext;
44
45         void    *ThreadHandle;
46          int    TID;
47
48          int    Status;
49
50         tShortSpinlock  IsLocked;
51
52         uint32_t        EventState;
53         uint32_t        WaitingEvents;
54         tThreadIntSem   *WaitSemaphore; // pthreads
55
56         char    *ThreadName;
57
58          int    bInstrTrace;    // Used for semaphore tracing
59
60          int    RetStatus;
61         void    *WaitPointer;
62
63         // Init Only
64         void    (*SpawnFcn)(void*);
65         void    *SpawnData;
66 };
67
68 enum eThreadStatus {
69         THREAD_STAT_NULL,       // Invalid process
70         THREAD_STAT_ACTIVE,     // Running and schedulable process
71         THREAD_STAT_SLEEPING,   // Message Sleep
72         THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
73         THREAD_STAT_RWLOCKSLEEP,        // Read-Writer lock Sleep
74         THREAD_STAT_SEMAPHORESLEEP,     // Semaphore Sleep
75         THREAD_STAT_QUEUESLEEP, // Queue
76         THREAD_STAT_EVENTSLEEP, // Event sleep
77         THREAD_STAT_WAITING,    // ??? (Waiting for a thread)
78         THREAD_STAT_PREINIT,    // Being created
79         THREAD_STAT_ZOMBIE,     // Died/Killed, but parent not informed
80         THREAD_STAT_DEAD,       // Awaiting burial (free)
81         THREAD_STAT_BURIED      // If it's still on the list here, something's wrong
82 };
83 static const char * const casTHREAD_STAT[] = {
84         "THREAD_STAT_NULL",
85         "THREAD_STAT_ACTIVE",
86         "THREAD_STAT_SLEEPING",
87         "THREAD_STAT_MUTEXSLEEP",
88         "THREAD_STAT_RWLOCKSLEEP",
89         "THREAD_STAT_SEMAPHORESLEEP",
90         "THREAD_STAT_QUEUESLEEP",
91         "THREAD_STAT_EVENTSLEEP",
92         "THREAD_STAT_WAITING",
93         "THREAD_STAT_PREINIT",
94         "THREAD_STAT_ZOMBIE",
95         "THREAD_STAT_DEAD",
96         "THREAD_STAT_BURIED"
97 };
98
99 extern struct sThread __thread  *lpThreads_This;
100 extern tShortSpinlock   glThreadListLock;
101
102 extern int      Threads_int_CreateThread(struct sThread *Thread);
103 extern int      Threads_int_ThreadingEnabled(void);
104
105
106 extern struct sThread   *Proc_GetCurThread(void);
107 extern struct sThread   *Threads_RemActive(void);
108 extern void     Threads_AddActive(struct sThread *Thread);
109 extern void     Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
110 extern int      Threads_int_Sleep(enum eThreadStatus Status, void *Ptr, int Num, struct sThread **ListHead, struct sThread **ListTail, tShortSpinlock *Lock);
111 extern void     Semaphore_ForceWake(struct sThread *Thread);
112
113 extern tThreadIntMutex  *Threads_int_MutexCreate(void);
114 extern void     Threads_int_MutexDestroy(tThreadIntMutex *Mutex);
115 extern void     Threads_int_MutexLock(tThreadIntMutex *Mutex);
116 extern void     Threads_int_MutexRelease(tThreadIntMutex *Mutex);
117
118 extern tThreadIntSem    *Threads_int_SemCreate(void);
119 extern void     Threads_int_SemDestroy(tThreadIntSem *Sem);
120 extern void     Threads_int_SemSignal(tThreadIntSem *Sem);
121 extern void     Threads_int_SemWait(tThreadIntSem *Sem);
122 extern void     Threads_int_SemWaitAll(tThreadIntSem *Sem);
123
124 #endif
125

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