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>
13 typedef struct sThread tThread;
15 #define THREAD_EVENT_RWLOCK (1 << 8)
17 typedef struct sThreadIntMutex tThreadIntMutex; // actually pthreads
18 typedef struct sThreadIntSem tThreadIntSem;
22 struct sProcess *Next;
23 struct sThread *Threads;
38 struct sThread *ListNext;
40 struct sProcess *Process;
41 struct sThread *ProcNext;
48 tShortSpinlock IsLocked;
50 uint32_t PendingEvents;
51 uint32_t WaitingEvents;
52 tThreadIntSem *WaitSemaphore; // pthreads
56 int bInstrTrace; // Used for semaphore tracing
62 void (*SpawnFcn)(void*);
67 THREAD_STAT_NULL, // Invalid process
68 THREAD_STAT_ACTIVE, // Running and schedulable process
69 THREAD_STAT_SLEEPING, // Message Sleep
70 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
71 THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep
72 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
73 THREAD_STAT_QUEUESLEEP, // Queue
74 THREAD_STAT_EVENTSLEEP, // Event sleep
75 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
76 THREAD_STAT_PREINIT, // Being created
77 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
78 THREAD_STAT_DEAD, // Awaiting burial (free)
79 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
81 static const char * const casTHREAD_STAT[] = {
84 "THREAD_STAT_SLEEPING",
85 "THREAD_STAT_MUTEXSLEEP",
86 "THREAD_STAT_RWLOCKSLEEP",
87 "THREAD_STAT_SEMAPHORESLEEP",
88 "THREAD_STAT_QUEUESLEEP",
89 "THREAD_STAT_EVENTSLEEP",
90 "THREAD_STAT_WAITING",
91 "THREAD_STAT_PREINIT",
97 extern struct sThread __thread *lpThreads_This;
98 extern tShortSpinlock glThreadListLock;
100 extern int Threads_int_CreateThread(struct sThread *Thread);
101 extern int Threads_int_ThreadingEnabled(void);
103 extern tThread *Proc_GetCurThread(void);
104 extern tThread *Threads_RemActive(void);
105 extern void Threads_AddActive(tThread *Thread);
106 extern void Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
108 extern tThreadIntMutex *Threads_int_MutexCreate(void);
109 extern void Threads_int_MutexDestroy(tThreadIntMutex *Mutex);
110 extern void Threads_int_MutexLock(tThreadIntMutex *Mutex);
111 extern void Threads_int_MutexRelease(tThreadIntMutex *Mutex);
113 extern tThreadIntSem *Threads_int_SemCreate(void);
114 extern void Threads_int_SemDestroy(tThreadIntSem *Sem);
115 extern void Threads_int_SemSignal(tThreadIntSem *Sem);
116 extern void Threads_int_SemWait(tThreadIntSem *Sem);
117 extern void Threads_int_SemWaitAll(tThreadIntSem *Sem);