Kernel - Commenting changes only
[tpg/acess2.git] / KernelLand / Kernel / include / threads_int.h
1 /*
2  * Acess2 Kernel
3  * - By John Hodge (thePowersGang)
4  *
5  * include/threads_int.h
6  * - Internal Threading header
7  * - Only for use by stuff that needs access to the thread type.
8  */
9 #ifndef _THREADS_INT_H_
10 #define _THREADS_INT_H_
11
12 #include <threads.h>
13 #include <proc.h>
14 #include <timers_int.h>
15
16 typedef struct sProcess tProcess;
17
18 /**
19  * \brief IPC Message
20  */
21 typedef struct sMessage
22 {
23         struct sMessage *Next;  //!< Next message in thread's inbox
24         tTID    Source; //!< Source thread ID
25         Uint    Length; //!< Length of message data in bytes
26         Uint8   Data[]; //!< Message data
27 } tMsg;
28
29 /**
30  * \brief Process state
31  */
32 struct sProcess
33 {
34         struct sProcess *Next;
35         tPGID   PGID;
36         tPID    PID;
37
38          int    nThreads;
39         struct sThread  *FirstThread;
40         
41         tUID    UID;    //!< User ID
42         tGID    GID;    //!< User and Group
43         tMemoryState    MemState;
44
45          int    MaxFD;
46         char    *CurrentWorkingDir;
47         char    *RootDir;
48 };
49
50 /**
51  * \brief Core threading structure
52  * 
53  */
54 struct sThread
55 {
56         // --- threads.c's
57         /**
58          * \brief Next thread in current list
59          * \note Required to be first for linked list hacks to work
60          */
61         struct sThread  *Next;
62         struct sThread  *GlobalNext;    //!< Next thread in global list
63         struct sThread  *GlobalPrev;    //!< Previous thread in global list
64         struct sThread  *ProcessNext;
65         tShortSpinlock  IsLocked;       //!< Thread's spinlock
66         volatile int    Status;         //!< Thread Status
67         void    *WaitPointer;   //!< What (Mutex/Thread/other) is the thread waiting on
68          int    RetStatus;      //!< Return Status
69         
70         tTID    TID;    //!< Thread ID
71         struct sProcess *Process;       //!< Thread Group / Process
72         struct sThread  *Parent;        //!< Parent Thread
73         char    *ThreadName;    //!< Name of thread
74         
75         // --- arch/proc.c's responsibility
76         //! Kernel Stack Base
77         tVAddr  KernelStack;
78         
79         //! State on task switch
80         tTaskState      SavedState;
81         
82         // --- threads.c's
83          int    CurFaultNum;    //!< Current fault number, 0: none
84         tVAddr  FaultHandler;   //!< Fault Handler
85         
86         tMsg * volatile Messages;       //!< Message Queue
87         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
88         
89          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
90          int    Priority;       //!< Priority - 0: Realtime, higher means less time
91         
92          int    _errno;
93         
94         volatile int    CurCPU;
95         
96         bool    bInstrTrace;
97         
98         // --- event.c
99         Uint32  EventState;
100         // --- timer.c
101         tTimer  ThreadTimer;
102 };
103
104
105 enum eThreadStatus {
106         THREAD_STAT_NULL,       // Invalid process
107         THREAD_STAT_ACTIVE,     // Running and schedulable process
108         THREAD_STAT_SLEEPING,   // Message Sleep
109         THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
110         THREAD_STAT_RWLOCKSLEEP,        // Read-Writer lock Sleep
111         THREAD_STAT_SEMAPHORESLEEP,     // Semaphore Sleep
112         THREAD_STAT_QUEUESLEEP, // Queue
113         THREAD_STAT_EVENTSLEEP, // Event sleep
114         THREAD_STAT_WAITING,    // ??? (Waiting for a thread)
115         THREAD_STAT_PREINIT,    // Being created
116         THREAD_STAT_ZOMBIE,     // Died/Killed, but parent not informed
117         THREAD_STAT_DEAD,       // Awaiting burial (free)
118         THREAD_STAT_BURIED      // If it's still on the list here, something's wrong
119 };
120 static const char * const casTHREAD_STAT[] = {
121         "THREAD_STAT_NULL",
122         "THREAD_STAT_ACTIVE",
123         "THREAD_STAT_SLEEPING",
124         "THREAD_STAT_MUTEXSLEEP",
125         "THREAD_STAT_SEMAPHORESLEEP",
126         "THREAD_STAT_QUEUESLEEP",
127         "THREAD_STAT_EVENTSLEEP",
128         "THREAD_STAT_WAITING",
129         "THREAD_STAT_PREINIT",
130         "THREAD_STAT_ZOMBIE",
131         "THREAD_STAT_DEAD",
132         "THREAD_STAT_BURIED"
133 };
134
135 // === GLOBALS ===
136 extern BOOL     gaThreads_NoTaskSwitch[MAX_CPUS];
137 extern tShortSpinlock   glThreadListLock;
138
139 // === FUNCTIONS ===
140 extern tThread  *Threads_GetThread(Uint TID);
141 extern void     Threads_SetPriority(tThread *Thread, int Pri);
142 extern int      Threads_Wake(tThread *Thread);
143 extern void     Threads_Kill(tThread *Thread, int Status);
144 extern void     Threads_AddActive(tThread *Thread);
145 extern tThread  *Threads_RemActive(void);
146 extern void     Threads_Delete(tThread *Thread);
147 extern tThread  *Threads_GetNextToRun(int CPU, tThread *Last);
148
149 extern tThread  *Threads_CloneTCB(Uint Flags);
150 extern tThread  *Threads_CloneThreadZero(void);
151
152 #endif

UCC git Repository :: git.ucc.asn.au