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>
15 #include <posix_signals.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;
36 struct sProcess *Prev;
41 struct sThread *FirstThread;
43 tUID UID; //!< User ID
44 tGID GID; //!< User and Group
45 tMemoryState MemState;
48 char *CurrentWorkingDir;
51 void *SignalHandlers[NSIGNALS];
55 * \brief Core threading structure
62 * \brief Next thread in current list
63 * \note Required to be first for linked list hacks to work
66 struct sThread *GlobalNext; //!< Next thread in global list
67 struct sThread *GlobalPrev; //!< Previous thread in global list
68 struct sThread *ProcessNext;
69 tShortSpinlock IsLocked; //!< Thread's spinlock
70 volatile int Status; //!< Thread Status
71 void *WaitPointer; //!< What (Mutex/Thread/other) is the thread waiting on
72 int RetStatus; //!< Return Status
74 tTID TID; //!< Thread ID
75 struct sProcess *Process; //!< Thread Group / Process
76 struct sThread *Parent; //!< Parent Thread
77 char *ThreadName; //!< Name of thread
79 struct sThread *LastDeadChild; //!< Last child to die (will have the \a DeadChildren lock)
80 tMutex DeadChildLock; //!< Lock to prevent clobbering of \a LastDeadChild, acquired by child, released by parent
82 // --- arch/proc.c's responsibility
86 //! State on task switch
87 tTaskState SavedState;
90 int CurFaultNum; //!< Current fault number, 0: none
91 tVAddr FaultHandler; //!< Fault Handler
94 int PendingSignal; //!< Pending signal ID (0 = none)
97 tMsg * volatile Messages; //!< Message Queue
98 tMsg *LastMessage; //!< Last Message (speeds up insertion)
100 int Quantum, Remaining; //!< Quantum Size and remaining timesteps
101 int Priority; //!< Priority - 0: Realtime, higher means less time
117 THREAD_STAT_NULL, // Invalid process
118 THREAD_STAT_ACTIVE, // Running and schedulable process
119 THREAD_STAT_SLEEPING, // Message Sleep
120 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
121 THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep
122 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
123 THREAD_STAT_QUEUESLEEP, // Queue
124 THREAD_STAT_EVENTSLEEP, // Event sleep
125 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
126 THREAD_STAT_PREINIT, // Being created
127 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
128 THREAD_STAT_DEAD, // Awaiting burial (free)
129 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
131 static const char * const casTHREAD_STAT[] = {
133 "THREAD_STAT_ACTIVE",
134 "THREAD_STAT_SLEEPING",
135 "THREAD_STAT_MUTEXSLEEP",
136 "THREAD_STAT_RWLOCKSLEEP",
137 "THREAD_STAT_SEMAPHORESLEEP",
138 "THREAD_STAT_QUEUESLEEP",
139 "THREAD_STAT_EVENTSLEEP",
140 "THREAD_STAT_WAITING",
141 "THREAD_STAT_PREINIT",
142 "THREAD_STAT_ZOMBIE",
148 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
149 extern tShortSpinlock glThreadListLock;
152 extern tThread *Threads_GetThread(Uint TID);
153 extern void Threads_SetPriority(tThread *Thread, int Pri);
154 extern int Threads_Wake(tThread *Thread);
155 extern void Threads_Kill(tThread *Thread, int Status);
156 extern void Threads_AddActive(tThread *Thread);
157 extern tThread *Threads_RemActive(void);
158 extern void Threads_Delete(tThread *Thread);
159 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
161 extern tThread *Threads_CloneTCB(Uint Flags);
162 extern tThread *Threads_CloneThreadZero(void);
164 extern int Threads_int_Sleep(enum eThreadStatus Status, void *Ptr, int Num, tThread **ListHead, tThread **ListTail, tShortSpinlock *Lock);
165 extern void Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
166 extern void Semaphore_ForceWake(tThread *Thread);