715be8c08ae5646a31d030d400db5388ac4cc451
[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         //  0
22         struct sThread  *Next;  //!< Next thread in list
23         tSpinlock       IsLocked;       //!< Thread's spinlock
24         volatile int    Status;         //!< Thread Status
25          int    RetStatus;      //!< Return Status
26         
27         // 16
28         Uint    TID;    //!< Thread ID
29         Uint    TGID;   //!< Thread Group (Process)
30         Uint    PTID;   //!< Parent Thread ID
31         Uint    UID, GID;       //!< User and Group
32         char    *ThreadName;    //!< Name of thread
33         
34         // --- arch/proc.c's responsibility
35         // 40
36         //! Kernel Stack Base
37         tVAddr  KernelStack;
38         
39         // 44 (x86)
40         //! Memory Manager State
41         tMemoryState    MemState;
42         
43         // 48 (x86)
44         //! State on task switch
45         tTaskState      SavedState;
46         
47         // --- threads.c's
48         // 60
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         // --- proc.c's
61         volatile int    CurCPU;
62 } tThread;
63
64
65 enum {
66         THREAD_STAT_NULL,
67         THREAD_STAT_ACTIVE,
68         THREAD_STAT_SLEEPING,
69         THREAD_STAT_WAITING,
70         THREAD_STAT_ZOMBIE,
71         THREAD_STAT_DEAD
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_Wake(tThread *Thread);
90 extern void     Threads_AddActive(tThread *Thread);
91 extern tThread  *Threads_GetNextToRun(int CPU, tThread *Last);
92
93 #endif

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