3 * - By John Hodge (thePowersGang)
5 * include/threads_int.h
6 * - Internal Threading header
7 * - Only for use by stuff that needs access to the thread type.
9 #ifndef _THREADS_INT_H_
10 #define _THREADS_INT_H_
14 #include <timers_int.h>
16 typedef struct sProcess tProcess;
21 typedef struct sMessage
23 struct sMessage *Next; //!< Next message in thread's inbox
24 tTID Source; //!< Source thread ID
25 Uint Length; //!< Length of message data in bytes
26 Uint8 Data[]; //!< Message data
30 * \brief Process state
34 struct sProcess *Next;
39 struct sThread *FirstThread;
41 tUID UID; //!< User ID
42 tGID GID; //!< User and Group
43 tMemoryState MemState;
46 char *CurrentWorkingDir;
51 * \brief Core threading structure
58 * \brief Next thread in current list
59 * \note Required to be first for linked list hacks to work
62 struct sThread *GlobalNext; //!< Next thread in global list
63 struct sThread *GlobalPrev; //!< Previous thread in global list
64 struct sThread *ProcessNext;
65 tShortSpinlock IsLocked; //!< Thread's spinlock
66 volatile int Status; //!< Thread Status
67 void *WaitPointer; //!< What (Mutex/Thread/other) is the thread waiting on
68 int RetStatus; //!< Return Status
70 tTID TID; //!< Thread ID
71 struct sProcess *Process; //!< Thread Group / Process
72 struct sThread *Parent; //!< Parent Thread
73 char *ThreadName; //!< Name of thread
75 // --- arch/proc.c's responsibility
79 //! State on task switch
80 tTaskState SavedState;
83 int CurFaultNum; //!< Current fault number, 0: none
84 tVAddr FaultHandler; //!< Fault Handler
86 tMsg * volatile Messages; //!< Message Queue
87 tMsg *LastMessage; //!< Last Message (speeds up insertion)
89 int Quantum, Remaining; //!< Quantum Size and remaining timesteps
90 int Priority; //!< Priority - 0: Realtime, higher means less time
106 THREAD_STAT_NULL, // Invalid process
107 THREAD_STAT_ACTIVE, // Running and schedulable process
108 THREAD_STAT_SLEEPING, // Message Sleep
109 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
110 THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep
111 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
112 THREAD_STAT_QUEUESLEEP, // Queue
113 THREAD_STAT_EVENTSLEEP, // Event sleep
114 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
115 THREAD_STAT_PREINIT, // Being created
116 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
117 THREAD_STAT_DEAD, // Awaiting burial (free)
118 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
120 static const char * const casTHREAD_STAT[] = {
122 "THREAD_STAT_ACTIVE",
123 "THREAD_STAT_SLEEPING",
124 "THREAD_STAT_MUTEXSLEEP",
125 "THREAD_STAT_SEMAPHORESLEEP",
126 "THREAD_STAT_QUEUESLEEP",
127 "THREAD_STAT_EVENTSLEEP",
128 "THREAD_STAT_WAITING",
129 "THREAD_STAT_PREINIT",
130 "THREAD_STAT_ZOMBIE",
136 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
137 extern tShortSpinlock glThreadListLock;
140 extern tThread *Threads_GetThread(Uint TID);
141 extern void Threads_SetPriority(tThread *Thread, int Pri);
142 extern int Threads_Wake(tThread *Thread);
143 extern void Threads_Kill(tThread *Thread, int Status);
144 extern void Threads_AddActive(tThread *Thread);
145 extern tThread *Threads_RemActive(void);
146 extern void Threads_Delete(tThread *Thread);
147 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
149 extern tThread *Threads_CloneTCB(Uint Flags);
150 extern tThread *Threads_CloneThreadZero(void);