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>
17 typedef struct sProcess tProcess;
22 typedef struct sMessage
24 struct sMessage *Next; //!< Next message in thread's inbox
25 tTID Source; //!< Source thread ID
26 Uint Length; //!< Length of message data in bytes
27 Uint8 Data[]; //!< Message data
31 * \brief Process state
35 struct sProcess *Next;
40 struct sThread *FirstThread;
42 tUID UID; //!< User ID
43 tGID GID; //!< User and Group
44 tMemoryState MemState;
47 char *CurrentWorkingDir;
50 void *SignalHandlers[NSIGNALS];
54 * \brief Core threading structure
61 * \brief Next thread in current list
62 * \note Required to be first for linked list hacks to work
65 struct sThread *GlobalNext; //!< Next thread in global list
66 struct sThread *GlobalPrev; //!< Previous thread in global list
67 struct sThread *ProcessNext;
68 tShortSpinlock IsLocked; //!< Thread's spinlock
69 volatile int Status; //!< Thread Status
70 void *WaitPointer; //!< What (Mutex/Thread/other) is the thread waiting on
71 int RetStatus; //!< Return Status
73 tTID TID; //!< Thread ID
74 struct sProcess *Process; //!< Thread Group / Process
75 struct sThread *Parent; //!< Parent Thread
76 char *ThreadName; //!< Name of thread
78 struct sThread *LastDeadChild; //!< Last child to die (will have the \a DeadChildren lock)
79 tMutex DeadChildLock; //!< Lock to prevent clobbering of \a LastDeadChild, acquired by child, released by parent
81 // --- arch/proc.c's responsibility
85 //! State on task switch
86 tTaskState SavedState;
89 int CurFaultNum; //!< Current fault number, 0: none
90 tVAddr FaultHandler; //!< Fault Handler
93 int PendingSignal; //!< Pending signal ID (0 = none)
96 tMsg * volatile Messages; //!< Message Queue
97 tMsg *LastMessage; //!< Last Message (speeds up insertion)
99 int Quantum, Remaining; //!< Quantum Size and remaining timesteps
100 int Priority; //!< Priority - 0: Realtime, higher means less time
116 THREAD_STAT_NULL, // Invalid process
117 THREAD_STAT_ACTIVE, // Running and schedulable process
118 THREAD_STAT_SLEEPING, // Message Sleep
119 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
120 THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep
121 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
122 THREAD_STAT_QUEUESLEEP, // Queue
123 THREAD_STAT_EVENTSLEEP, // Event sleep
124 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
125 THREAD_STAT_PREINIT, // Being created
126 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
127 THREAD_STAT_DEAD, // Awaiting burial (free)
128 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
130 static const char * const casTHREAD_STAT[] = {
132 "THREAD_STAT_ACTIVE",
133 "THREAD_STAT_SLEEPING",
134 "THREAD_STAT_MUTEXSLEEP",
135 "THREAD_STAT_RWLOCKSLEEP",
136 "THREAD_STAT_SEMAPHORESLEEP",
137 "THREAD_STAT_QUEUESLEEP",
138 "THREAD_STAT_EVENTSLEEP",
139 "THREAD_STAT_WAITING",
140 "THREAD_STAT_PREINIT",
141 "THREAD_STAT_ZOMBIE",
147 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
148 extern tShortSpinlock glThreadListLock;
151 extern tThread *Threads_GetThread(Uint TID);
152 extern void Threads_SetPriority(tThread *Thread, int Pri);
153 extern int Threads_Wake(tThread *Thread);
154 extern void Threads_Kill(tThread *Thread, int Status);
155 extern void Threads_AddActive(tThread *Thread);
156 extern tThread *Threads_RemActive(void);
157 extern void Threads_Delete(tThread *Thread);
158 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
160 extern tThread *Threads_CloneTCB(Uint Flags);
161 extern tThread *Threads_CloneThreadZero(void);
163 extern void Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
164 extern void Semaphore_ForceWake(tThread *Thread);