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

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