6c29230763d587f37f1c265543e77113ead4644e
[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         struct sThread  *Next;  //!< Next thread in list
22         tShortSpinlock  IsLocked;       //!< Thread's spinlock
23         volatile int    Status;         //!< Thread Status
24          int    RetStatus;      //!< Return Status
25         
26         Uint    TID;    //!< Thread ID
27         Uint    TGID;   //!< Thread Group (Process)
28         Uint    PTID;   //!< Parent Thread ID
29         Uint    UID, GID;       //!< User and Group
30         char    *ThreadName;    //!< Name of thread
31         
32         // --- arch/proc.c's responsibility
33         //! Kernel Stack Base
34         tVAddr  KernelStack;
35         
36         //! Memory Manager State
37         tMemoryState    MemState;
38         
39         //! State on task switch
40         tTaskState      SavedState;
41         
42         // --- threads.c's
43          int    CurFaultNum;    //!< Current fault number, 0: none
44         tVAddr  FaultHandler;   //!< Fault Handler
45         
46         tMsg * volatile Messages;       //!< Message Queue
47         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
48         
49          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
50          int    NumTickets;     //!< Priority - Chance of gaining CPU
51         
52         Uint    Config[NUM_CFG_ENTRIES];        //!< Per-process configuration
53         
54         volatile int    CurCPU;
55 } tThread;
56
57
58 enum {
59         THREAD_STAT_NULL,
60         THREAD_STAT_ACTIVE,
61         THREAD_STAT_SLEEPING,
62         THREAD_STAT_WAITING,
63         THREAD_STAT_ZOMBIE,
64         THREAD_STAT_DEAD
65 };
66
67 enum eFaultNumbers
68 {
69         FAULT_MISC,
70         FAULT_PAGE,
71         FAULT_ACCESS,
72         FAULT_DIV0,
73         FAULT_OPCODE,
74         FAULT_FLOAT
75 };
76
77 #define GETMSG_IGNORE   ((void*)-1)
78
79 // === FUNCTIONS ===
80 extern tThread  *Proc_GetCurThread(void);
81 extern tThread  *Threads_GetThread(Uint TID);
82 extern void     Threads_SetTickets(tThread *Thread, int Num);
83 extern int      Threads_Wake(tThread *Thread);
84 extern void     Threads_AddActive(tThread *Thread);
85 extern tThread  *Threads_GetNextToRun(int CPU, tThread *Last);
86
87 #endif

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