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_
11 typedef struct sProcess tProcess;
16 typedef struct sMessage
18 struct sMessage *Next; //!< Next message in thread's inbox
19 tTID Source; //!< Source thread ID
20 Uint Length; //!< Length of message data in bytes
21 Uint8 Data[]; //!< Message data
25 * \brief Process state
29 struct sProcess *Next;
34 struct sThread *FirstThread;
36 tUID UID; //!< User ID
37 tGID GID; //!< User and Group
38 tMemoryState MemState;
41 char *CurrentWorkingDir;
46 * \brief Core threading structure
53 * \brief Next thread in current list
54 * \note Required to be first for linked list hacks to work
57 struct sThread *GlobalNext; //!< Next thread in global list
58 struct sThread *GlobalPrev; //!< Previous thread in global list
59 struct sThread *ProcessNext;
60 tShortSpinlock IsLocked; //!< Thread's spinlock
61 volatile int Status; //!< Thread Status
62 void *WaitPointer; //!< What (Mutex/Thread/other) is the thread waiting on
63 int RetStatus; //!< Return Status
65 tTID TID; //!< Thread ID
66 struct sProcess *Process; //!< Thread Group / Process
67 struct sThread *Parent; //!< Parent Thread
68 char *ThreadName; //!< Name of thread
70 // --- arch/proc.c's responsibility
74 //! State on task switch
75 tTaskState SavedState;
78 int CurFaultNum; //!< Current fault number, 0: none
79 tVAddr FaultHandler; //!< Fault Handler
81 tMsg * volatile Messages; //!< Message Queue
82 tMsg *LastMessage; //!< Last Message (speeds up insertion)
84 int Quantum, Remaining; //!< Quantum Size and remaining timesteps
85 int Priority; //!< Priority - 0: Realtime, higher means less time
99 THREAD_STAT_NULL, // Invalid process
100 THREAD_STAT_ACTIVE, // Running and schedulable process
101 THREAD_STAT_SLEEPING, // Message Sleep
102 THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
103 THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep
104 THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
105 THREAD_STAT_QUEUESLEEP, // Queue
106 THREAD_STAT_EVENTSLEEP, // Event sleep
107 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
108 THREAD_STAT_PREINIT, // Being created
109 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
110 THREAD_STAT_DEAD, // Awaiting burial (free)
111 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
113 static const char * const casTHREAD_STAT[] = {
115 "THREAD_STAT_ACTIVE",
116 "THREAD_STAT_SLEEPING",
117 "THREAD_STAT_MUTEXSLEEP",
118 "THREAD_STAT_SEMAPHORESLEEP",
119 "THREAD_STAT_QUEUESLEEP",
120 "THREAD_STAT_EVENTSLEEP",
121 "THREAD_STAT_WAITING",
122 "THREAD_STAT_PREINIT",
123 "THREAD_STAT_ZOMBIE",
129 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
130 extern tShortSpinlock glThreadListLock;
133 extern tThread *Threads_GetThread(Uint TID);
134 extern void Threads_SetPriority(tThread *Thread, int Pri);
135 extern int Threads_Wake(tThread *Thread);
136 extern void Threads_Kill(tThread *Thread, int Status);
137 extern void Threads_AddActive(tThread *Thread);
138 extern tThread *Threads_RemActive(void);
139 extern void Threads_Delete(tThread *Thread);
140 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
142 extern tThread *Threads_CloneTCB(Uint Flags);
143 extern tThread *Threads_CloneThreadZero(void);