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_SEMAPHORESLEEP, // Semaphore Sleep
104 THREAD_STAT_QUEUESLEEP, // Queue
105 THREAD_STAT_EVENTSLEEP, // Event sleep
106 THREAD_STAT_WAITING, // ??? (Waiting for a thread)
107 THREAD_STAT_PREINIT, // Being created
108 THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
109 THREAD_STAT_DEAD, // Awaiting burial (free)
110 THREAD_STAT_BURIED // If it's still on the list here, something's wrong
112 static const char * const casTHREAD_STAT[] = {
114 "THREAD_STAT_ACTIVE",
115 "THREAD_STAT_SLEEPING",
116 "THREAD_STAT_MUTEXSLEEP",
117 "THREAD_STAT_SEMAPHORESLEEP",
118 "THREAD_STAT_QUEUESLEEP",
119 "THREAD_STAT_EVENTSLEEP",
120 "THREAD_STAT_WAITING",
121 "THREAD_STAT_PREINIT",
122 "THREAD_STAT_ZOMBIE",
128 extern BOOL gaThreads_NoTaskSwitch[MAX_CPUS];
129 extern tShortSpinlock glThreadListLock;
132 extern tThread *Threads_GetThread(Uint TID);
133 extern void Threads_SetPriority(tThread *Thread, int Pri);
134 extern int Threads_Wake(tThread *Thread);
135 extern void Threads_Kill(tThread *Thread, int Status);
136 extern void Threads_AddActive(tThread *Thread);
137 extern tThread *Threads_RemActive(void);
138 extern void Threads_Delete(tThread *Thread);
139 extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
141 extern tThread *Threads_CloneTCB(Uint Flags);
142 extern tThread *Threads_CloneThreadZero(void);