2 * Acess2 libnative (Kernel Simulation Library)
3 * - By John Hodge (thePowersGang)
6 * - Threads handling definitions
8 #ifndef _THREADS_INT_H_
9 #define _THREADS_INT_H_
11 #include <shortlock.h>
14 typedef struct sThread tThread;
17 #define THREAD_EVENT_RWLOCK (1 << 8)
19 typedef struct sThreadIntMutex tThreadIntMutex; // actually pthreads
20 typedef struct sThreadIntSem tThreadIntSem;
24 struct sProcess *Next;
25 struct sThread *Threads;
40 struct sThread *ListNext;
42 struct sProcess *Process;
43 struct sThread *ProcNext;
50 tShortSpinlock IsLocked;
53 uint32_t WaitingEvents;
54 tThreadIntSem *WaitSemaphore; // pthreads
58 int bInstrTrace; // Used for semaphore tracing
64 void (*SpawnFcn)(void*);
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
83 static const char * const casTHREAD_STAT[] = {
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",
99 extern struct sThread __thread *lpThreads_This;
100 extern tShortSpinlock glThreadListLock;
102 extern int Threads_int_CreateThread(struct sThread *Thread);
103 extern int Threads_int_ThreadingEnabled(void);
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);
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);
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);