2 * Internal Threading header
3 * - Only for use by stuff that needs access to the thread type.
5 #ifndef _THREADS_INT_H_
6 #define _THREADS_INT_H_
12 typedef struct sProcess tProcess;
17 typedef struct sMessage
19 struct sMessage *Next; //!< Next message in thread's inbox
20 tTID Source; //!< Source thread ID
21 Uint Length; //!< Length of message data in bytes
22 Uint8 Data[]; //!< Message data
26 * \brief Process state
33 tUID UID; //!< User ID
34 tGID GID; //!< User and Group
35 tMemoryState MemState;
38 char *CurrentWorkingDir;
43 * \brief Core threading structure
50 * \brief Next thread in current list
51 * \note Required to be first for linked list hacks to work
54 struct sThread *GlobalNext; //!< Next thread in global list
55 struct sThread *GlobalPrev; //!< Previous thread in global list
56 tShortSpinlock IsLocked; //!< Thread's spinlock
57 volatile int Status; //!< Thread Status
58 void *WaitPointer; //!< What (Mutex/Thread/other) is the thread waiting on
59 int RetStatus; //!< Return Status
61 tTID TID; //!< Thread ID
62 struct sProcess *Process; //!< Thread Group / Process
63 struct sThread *Parent; //!< Parent Thread
64 char *ThreadName; //!< Name of thread
66 // --- arch/proc.c's responsibility
70 //! State on task switch
71 tTaskState SavedState;
74 int CurFaultNum; //!< Current fault number, 0: none
75 tVAddr FaultHandler; //!< Fault Handler
77 tMsg * volatile Messages; //!< Message Queue
78 tMsg *LastMessage; //!< Last Message (speeds up insertion)
80 int Quantum, Remaining; //!< Quantum Size and remaining timesteps
81 int Priority; //!< Priority - 0: Realtime, higher means less time
95 THREAD_STAT_NULL, // Invalid process
96 THREAD_STAT_ACTIVE, // Running and schedulable process
97 THREAD_STAT_SLEEPING, // Message Sleep
98 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
99 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
100 THREAD_STAT_QUEUESLEEP, // Queue
101 THREAD_STAT_EVENTSLEEP, // Event sleep
102 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
103 THREAD_STAT_PREINIT, // Being created
104 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
105 THREAD_STAT_DEAD, // Awaiting burial (free)
106 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
108 static const char * const casTHREAD_STAT[] = {
110 "THREAD_STAT_ACTIVE",
111 "THREAD_STAT_SLEEPING",
112 "THREAD_STAT_MUTEXSLEEP",
113 "THREAD_STAT_SEMAPHORESLEEP",
114 "THREAD_STAT_QUEUESLEEP",
115 "THREAD_STAT_EVENTSLEEP",
116 "THREAD_STAT_WAITING",
117 "THREAD_STAT_PREINIT",
118 "THREAD_STAT_ZOMBIE",
124 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
125 extern tShortSpinlock glThreadListLock;
128 extern tThread *Proc_GetCurThread(void);
130 extern tThread *Threads_GetThread(Uint TID);
131 extern void Threads_SetPriority(tThread *Thread, int Pri);
132 extern int Threads_Wake(tThread *Thread);
133 extern void Threads_Kill(tThread *Thread, int Status);
134 extern void Threads_AddActive(tThread *Thread);
135 extern tThread *Threads_RemActive(void);
136 extern void Threads_Delete(tThread *Thread);
137 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
139 extern tThread *Threads_CloneTCB(Uint Flags);
140 extern tThread *Threads_CloneThreadZero(void);