00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _RTAI_NUCLEUS_THREAD_H
00021 #define _RTAI_NUCLEUS_THREAD_H
00022
00023 #include <nucleus/timer.h>
00024
00025
00026 #define XNSUSP 0x00000001
00027 #define XNPEND 0x00000002
00028 #define XNDELAY 0x00000004
00029 #define XNREADY 0x00000008
00030 #define XNDORMANT 0x00000010
00031 #define XNZOMBIE 0x00000020
00032 #define XNRESTART 0x00000040
00033 #define XNSTARTED 0x00000080
00034 #define XNRELAX 0x00000100
00035
00036 #define XNTIMEO 0x00000200
00037 #define XNRMID 0x00000400
00038 #define XNBREAK 0x00000800
00039 #define XNKICKED 0x00001000
00040 #define XNBOOST 0x00002000
00041
00042
00043 #define XNLOCK 0x00004000
00044 #define XNRRB 0x00008000
00045 #define XNASDI 0x00010000
00046 #define XNSHIELD 0x00020000
00047 #define XNTRAPSW 0x00040000
00048
00049 #define XNFPU 0x00080000
00050 #define XNSHADOW 0x00100000
00051 #define XNROOT 0x00200000
00052
00053
00054 #define XNTHREAD_SLABEL_INIT { \
00055 "ssp", "pnd", "dly", "rdy", "dor", \
00056 "zom", "rst", "sta", "rlx", "tmo", \
00057 "rmi", "brk", "sig", "pip", "lck", \
00058 "rrb", "asd", "shl", "tsw", "fpu", \
00059 "usr", "idl" \
00060 }
00061
00062 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX)
00063 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNSHIELD|XNTRAPSW)
00064 #define XNTHREAD_SYSTEM_BITS (XNROOT)
00065
00066
00067 #define XNTHREAD_SPARE0 0x10000000
00068 #define XNTHREAD_SPARE1 0x20000000
00069 #define XNTHREAD_SPARE2 0x40000000
00070 #define XNTHREAD_SPARE3 0x80000000
00071 #define XNTHREAD_SPARES 0xf0000000
00072
00073 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00074
00075 #ifdef __RTAI_SIM__
00076 #define XNRUNNING XNTHREAD_SPARE0
00077 #define XNDELETED XNTHREAD_SPARE1
00078 #endif
00079
00080 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
00081
00082 struct xnsched;
00083 struct xnsynch;
00084
00085 typedef void (*xnasr_t)(xnsigmask_t sigs);
00086
00087 typedef struct xnthread {
00088
00089 xnarchtcb_t tcb;
00090
00091 xnflags_t status;
00092
00093 struct xnsched *sched;
00094
00095 xnarch_cpumask_t affinity;
00096
00097 int bprio;
00098
00099 int cprio;
00100
00101 xnholder_t slink;
00102
00103 xnpholder_t rlink;
00104
00105 xnpholder_t plink;
00106
00107 xnholder_t glink;
00108
00109
00110 #define link2thread(laddr,link) \
00111 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00112
00113 xnpqueue_t claimq;
00114
00115 struct xnsynch *wchan;
00116
00117 xntimer_t rtimer;
00118
00119 xntimer_t ptimer;
00120
00121 int poverrun;
00122
00123 xnsigmask_t signals;
00124
00125 xnticks_t rrperiod;
00126
00127 xnticks_t rrcredit;
00128
00129 struct {
00130
00131 unsigned long psw;
00132 unsigned long ssw;
00133 unsigned long pf;
00134
00135 } stat;
00136
00137 xnasr_t asr;
00138
00139 xnflags_t asrmode;
00140
00141 int asrimask;
00142
00143 unsigned asrlevel;
00144
00145 int imask;
00146
00147 int imode;
00148
00149 int iprio;
00150
00151 unsigned magic;
00152
00153 char name[XNOBJECT_NAME_LEN];
00154
00155 xnticks_t stime;
00156
00157 void (*entry)(void *cookie);
00158
00159 void *cookie;
00160
00161 void *extinfo;
00162
00163 XNARCH_DECL_DISPLAY_CONTEXT();
00164
00165 } xnthread_t;
00166
00167 #define XNHOOK_THREAD_START 1
00168 #define XNHOOK_THREAD_SWITCH 2
00169 #define XNHOOK_THREAD_DELETE 3
00170
00171 typedef struct xnhook {
00172
00173 xnholder_t link;
00174
00175 #define link2hook(laddr) \
00176 ((xnhook_t *)(((char *)laddr) - (int)(&((xnhook_t *)0)->link)))
00177
00178 void (*routine)(xnthread_t *thread);
00179
00180 } xnhook_t;
00181
00182 #define xnthread_name(thread) ((thread)->name)
00183 #define xnthread_sched(thread) ((thread)->sched)
00184 #define xnthread_start_time(thread) ((thread)->stime)
00185 #define xnthread_status_flags(thread) ((thread)->status)
00186 #define xnthread_test_flags(thread,flags) testbits((thread)->status,flags)
00187 #define xnthread_set_flags(thread,flags) __setbits((thread)->status,flags)
00188 #define xnthread_clear_flags(thread,flags) __clrbits((thread)->status,flags)
00189 #define xnthread_initial_priority(thread) ((thread)->iprio)
00190 #define xnthread_base_priority(thread) ((thread)->bprio)
00191 #define xnthread_current_priority(thread) ((thread)->cprio)
00192 #define xnthread_time_slice(thread) ((thread)->rrperiod)
00193 #define xnthread_time_credit(thread) ((thread)->rrcredit)
00194 #define xnthread_archtcb(thread) (&((thread)->tcb))
00195 #define xnthread_asr_level(thread) ((thread)->asrlevel)
00196 #define xnthread_pending_signals(thread) ((thread)->signals)
00197 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
00198 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
00199 #define xnthread_extended_info(thread) ((thread)->extinfo)
00200 #define xnthread_set_magic(thread,m) do { (thread)->magic = (m); } while(0)
00201 #define xnthread_get_magic(thread) ((thread)->magic)
00202 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
00203 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
00204
00205 #ifdef __cplusplus
00206 extern "C" {
00207 #endif
00208
00209 int xnthread_init(xnthread_t *thread,
00210 const char *name,
00211 int prio,
00212 xnflags_t flags,
00213 unsigned stacksize);
00214
00215 void xnthread_cleanup_tcb(xnthread_t *thread);
00216
00217 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00218
00219 #ifdef __cplusplus
00220 }
00221 #endif
00222
00223 #endif
00224
00225 #endif