Sorting source tree a bit
[tpg/acess2.git] / KernelLand / Kernel / include / threads_int.h
1 /*
2  * Internal Threading header
3  * - Only for use by stuff that needs access to the thread type.
4  */
5 #ifndef _THREADS_INT_H_
6 #define _THREADS_INT_H_
7
8 #include <threads.h>
9 #include <proc.h>
10
11
12 typedef struct sProcess tProcess;
13
14 /**
15  * \brief IPC Message
16  */
17 typedef struct sMessage
18 {
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
23 } tMsg;
24
25 /**
26  * \brief Process state
27  */
28 struct sProcess
29 {
30         tPID    PID;
31          int    nThreads;
32         
33         tUID    UID;    //!< User ID
34         tGID    GID;    //!< User and Group
35         tMemoryState    MemState;
36
37          int    MaxFD;
38         char    *CurrentWorkingDir;
39         char    *RootDir;
40 };
41
42 /**
43  * \brief Core threading structure
44  * 
45  */
46 struct sThread
47 {
48         // --- threads.c's
49         /**
50          * \brief Next thread in current list
51          * \note Required to be first for linked list hacks to work
52          */
53         struct sThread  *Next;
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
60         
61         tTID    TID;    //!< Thread ID
62         struct sProcess *Process;       //!< Thread Group / Process
63         struct sThread  *Parent;        //!< Parent Thread
64         char    *ThreadName;    //!< Name of thread
65         
66         // --- arch/proc.c's responsibility
67         //! Kernel Stack Base
68         tVAddr  KernelStack;
69         
70         //! State on task switch
71         tTaskState      SavedState;
72         
73         // --- threads.c's
74          int    CurFaultNum;    //!< Current fault number, 0: none
75         tVAddr  FaultHandler;   //!< Fault Handler
76         
77         tMsg * volatile Messages;       //!< Message Queue
78         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
79         
80          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
81          int    Priority;       //!< Priority - 0: Realtime, higher means less time
82         
83          int    _errno;
84         
85         volatile int    CurCPU;
86         
87         bool    bInstrTrace;
88         
89         // --- event.c
90         Uint32  EventState;
91 };
92
93
94 enum {
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
107 };
108 static const char * const casTHREAD_STAT[] = {
109         "THREAD_STAT_NULL",
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",
119         "THREAD_STAT_DEAD",
120         "THREAD_STAT_BURIED"
121 };
122
123 // === GLOBALS ===
124 extern BOOL     gaThreads_NoTaskSwitch[MAX_CPUS];
125 extern tShortSpinlock   glThreadListLock;
126
127 // === FUNCTIONS ===
128 extern tThread  *Proc_GetCurThread(void);
129
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);
138
139 extern tThread  *Threads_CloneTCB(Uint Flags);
140 extern tThread  *Threads_CloneThreadZero(void);
141
142 #endif

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