Kernel - Added SwapEndian64 for SCSI code (coming)
[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 typedef struct sProcess tProcess;
12
13 /**
14  * \brief IPC Message
15  */
16 typedef struct sMessage
17 {
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
22 } tMsg;
23
24 /**
25  * \brief Process state
26  */
27 struct sProcess
28 {
29         struct sProcess *Next;
30         tPGID   PGID;
31         tPID    PID;
32
33          int    nThreads;
34         struct sThread  *FirstThread;
35         
36         tUID    UID;    //!< User ID
37         tGID    GID;    //!< User and Group
38         tMemoryState    MemState;
39
40          int    MaxFD;
41         char    *CurrentWorkingDir;
42         char    *RootDir;
43 };
44
45 /**
46  * \brief Core threading structure
47  * 
48  */
49 struct sThread
50 {
51         // --- threads.c's
52         /**
53          * \brief Next thread in current list
54          * \note Required to be first for linked list hacks to work
55          */
56         struct sThread  *Next;
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
64         
65         tTID    TID;    //!< Thread ID
66         struct sProcess *Process;       //!< Thread Group / Process
67         struct sThread  *Parent;        //!< Parent Thread
68         char    *ThreadName;    //!< Name of thread
69         
70         // --- arch/proc.c's responsibility
71         //! Kernel Stack Base
72         tVAddr  KernelStack;
73         
74         //! State on task switch
75         tTaskState      SavedState;
76         
77         // --- threads.c's
78          int    CurFaultNum;    //!< Current fault number, 0: none
79         tVAddr  FaultHandler;   //!< Fault Handler
80         
81         tMsg * volatile Messages;       //!< Message Queue
82         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
83         
84          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
85          int    Priority;       //!< Priority - 0: Realtime, higher means less time
86         
87          int    _errno;
88         
89         volatile int    CurCPU;
90         
91         bool    bInstrTrace;
92         
93         // --- event.c
94         Uint32  EventState;
95 };
96
97
98 enum {
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
111 };
112 static const char * const casTHREAD_STAT[] = {
113         "THREAD_STAT_NULL",
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",
123         "THREAD_STAT_DEAD",
124         "THREAD_STAT_BURIED"
125 };
126
127 // === GLOBALS ===
128 extern BOOL     gaThreads_NoTaskSwitch[MAX_CPUS];
129 extern tShortSpinlock   glThreadListLock;
130
131 // === FUNCTIONS ===
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);
140
141 extern tThread  *Threads_CloneTCB(Uint Flags);
142 extern tThread  *Threads_CloneThreadZero(void);
143
144 #endif

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