Kernel/ARMv7 - Fixed not using ASIDs
[tpg/acess2.git] / 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 /**
12  * \brief IPC Message
13  */
14 typedef struct sMessage
15 {
16         struct sMessage *Next;  //!< Next message in thread's inbox
17         tTID    Source; //!< Source thread ID
18         Uint    Length; //!< Length of message data in bytes
19         Uint8   Data[]; //!< Message data
20 } tMsg;
21
22 /**
23  * \brief Core threading structure
24  * 
25  */
26 typedef struct sThread
27 {
28         // --- threads.c's
29         /**
30          * \brief Next thread in current list
31          * \note Required to be first for linked list hacks to work
32          */
33         struct sThread  *Next;
34         struct sThread  *GlobalNext;    //!< Next thread in global list
35         struct sThread  *GlobalPrev;    //!< Previous thread in global list
36         tShortSpinlock  IsLocked;       //!< Thread's spinlock
37         volatile int    Status;         //!< Thread Status
38         void    *WaitPointer;   //!< What (Mutex/Thread/other) is the thread waiting on
39          int    RetStatus;      //!< Return Status
40         
41         Uint    TID;    //!< Thread ID
42         Uint    TGID;   //!< Thread Group (Process)
43         struct sThread  *Parent;        //!< Parent Thread
44         Uint    UID, GID;       //!< User and Group
45         char    *ThreadName;    //!< Name of thread
46         
47         // --- arch/proc.c's responsibility
48         //! Kernel Stack Base
49         tVAddr  KernelStack;
50         
51         //! Memory Manager State
52         tMemoryState    MemState;
53         
54         //! State on task switch
55         tTaskState      SavedState;
56         
57         // --- threads.c's
58          int    CurFaultNum;    //!< Current fault number, 0: none
59         tVAddr  FaultHandler;   //!< Fault Handler
60         
61         tMsg * volatile Messages;       //!< Message Queue
62         tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
63         
64          int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
65          int    Priority;       //!< Priority - 0: Realtime, higher means less time
66         
67         Uint    Config[NUM_CFG_ENTRIES];        //!< Per-process configuration
68         
69         volatile int    CurCPU;
70         
71          int    bInstrTrace;
72 } tThread;
73
74
75 enum {
76         THREAD_STAT_NULL,       // Invalid process
77         THREAD_STAT_ACTIVE,     // Running and schedulable process
78         THREAD_STAT_SLEEPING,   // Message Sleep
79         THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
80         THREAD_STAT_SEMAPHORESLEEP,     // Semaphore Sleep
81         THREAD_STAT_QUEUESLEEP, // Queue
82         THREAD_STAT_WAITING,    // ??? (Waiting for a thread)
83         THREAD_STAT_PREINIT,    // Being created
84         THREAD_STAT_ZOMBIE,     // Died/Killed, but parent not informed
85         THREAD_STAT_DEAD,       // Awaiting burial (free)
86         THREAD_STAT_BURIED      // If it's still on the list here, something's wrong
87 };
88 static const char * const casTHREAD_STAT[] = {
89         "THREAD_STAT_NULL",
90         "THREAD_STAT_ACTIVE",
91         "THREAD_STAT_SLEEPING",
92         "THREAD_STAT_MUTEXSLEEP",
93         "THREAD_STAT_SEMAPHORESLEEP",
94         "THREAD_STAT_QUEUESLEEP",
95         "THREAD_STAT_WAITING",
96         "THREAD_STAT_PREINIT",
97         "THREAD_STAT_ZOMBIE",
98         "THREAD_STAT_DEAD",
99         "THREAD_STAT_BURIED"
100 };
101
102 // === GLOBALS ===
103 extern BOOL     gaThreads_NoTaskSwitch[MAX_CPUS];
104 extern tShortSpinlock   glThreadListLock;
105
106 // === FUNCTIONS ===
107 extern tThread  *Proc_GetCurThread(void);
108
109 extern tThread  *Threads_GetThread(Uint TID);
110 extern void     Threads_SetPriority(tThread *Thread, int Pri);
111 extern int      Threads_Wake(tThread *Thread);
112 extern void     Threads_Kill(tThread *Thread, int Status);
113 extern void     Threads_AddActive(tThread *Thread);
114 extern tThread  *Threads_RemActive(void);
115 extern void     Threads_Delete(tThread *Thread);
116 extern tThread  *Threads_GetNextToRun(int CPU, tThread *Last);
117
118 extern tThread  *Threads_CloneTCB(Uint Flags);
119 extern tThread  *Threads_CloneThreadZero(void);
120
121 #endif

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