Per-CPU task switch disable, minor spiderscript changes
[tpg/acess2.git] / Kernel / include / threads.h
1 /*
2  */
3 #ifndef _THREADS_H_
4 #define _THREADS_H_
5
6 #include <arch.h>
7 #include <signal.h>
8 #include <proc.h>
9
10 /**
11  * \brief IPC Message
12  */
13 typedef struct sMessage
14 {
15         struct sMessage *Next;  //!< Next message in thread's inbox
16         tTID    Source; //!< Source thread ID
17         Uint    Length; //!< Length of message data in bytes
18         Uint8   Data[]; //!< Message data
19 } tMsg;
20
21 /**
22  * \brief Core threading structure
23  * 
24  */
25 typedef struct sThread
26 {
27         // --- threads.c's
28         /**
29          * \brief Next thread in current list
30          * \note Required to be first for linked list hacks to work
31          */
32         struct sThread  *Next;
33         struct sThread  *GlobalNext;    //!< Next thread in global list
34         struct sThread  *GlobalPrev;    //!< Previous thread in global list
35         tShortSpinlock  IsLocked;       //!< Thread's spinlock
36         volatile int    Status;         //!< Thread Status
37          int    RetStatus;      //!< Return Status
38         
39         Uint    TID;    //!< Thread ID
40         Uint    TGID;   //!< Thread Group (Process)
41         struct sThread  *Parent;        //!< Parent Thread
42         Uint    UID, GID;       //!< User and Group
43         char    *ThreadName;    //!< Name of thread
44         
45         // --- arch/proc.c's responsibility
46         //! Kernel Stack Base
47         tVAddr  KernelStack;
48         
49         //! Memory Manager State
50         tMemoryState    MemState;
51         
52         //! State on task switch
53         tTaskState      SavedState;
54         
55         // --- threads.c's
56          int    CurFaultNum;    //!< Current fault number, 0: none
57         tVAddr  FaultHandler;   //!< Fault Handler
58         
59         tMsg * volatile Messages;       //!< Message Queue
60         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
61         
62          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
63          int    NumTickets;     //!< Priority - Chance of gaining CPU
64         
65         Uint    Config[NUM_CFG_ENTRIES];        //!< Per-process configuration
66         
67         volatile int    CurCPU;
68 } tThread;
69
70
71 enum {
72         THREAD_STAT_NULL,       // Invalid process
73         THREAD_STAT_ACTIVE,     // Running and schedulable process
74         THREAD_STAT_SLEEPING,   // Message Sleep
75         THREAD_STAT_OFFSLEEP,   // Mutex Sleep (or waiting on a thread)
76         THREAD_STAT_WAITING,    // ???
77         THREAD_STAT_PREINIT,    // Being created
78         THREAD_STAT_ZOMBIE,     // Died, just not removed
79         THREAD_STAT_DEAD        // Why do we care about these???
80 };
81
82 enum eFaultNumbers
83 {
84         FAULT_MISC,
85         FAULT_PAGE,
86         FAULT_ACCESS,
87         FAULT_DIV0,
88         FAULT_OPCODE,
89         FAULT_FLOAT
90 };
91
92 #define GETMSG_IGNORE   ((void*)-1)
93
94 // === GLOBALS ===
95 extern BOOL     gaThreads_NoTaskSwitch[MAX_CPUS];
96
97 // === FUNCTIONS ===
98 extern tThread  *Proc_GetCurThread(void);
99 extern tThread  *Threads_GetThread(Uint TID);
100 extern void     Threads_SetTickets(tThread *Thread, int Num);
101 extern int      Threads_Wake(tThread *Thread);
102 extern void     Threads_AddActive(tThread *Thread);
103 extern tThread  *Threads_GetNextToRun(int CPU, tThread *Last);
104
105 #endif

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