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 #define XNDEBUG 0x00004000
00042
00043
00044 #define XNLOCK 0x00008000
00045 #define XNRRB 0x00010000
00046 #define XNASDI 0x00020000
00047 #define XNSHIELD 0x00040000
00048 #define XNTRAPSW 0x00080000
00049
00050 #define XNFPU 0x00100000
00051 #define XNSHADOW 0x00200000
00052 #define XNROOT 0x00400000
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define XNTHREAD_SLABEL_INIT { \
00072 'S', 'W', 'D', 'R', 'U', \
00073 '.', '.', '.', 'X', '.', \
00074 '.', '.', '.', 'b', 'T', \
00075 'l', 'r', '.', 's', 't', \
00076 'f', '.', '.' \
00077 }
00078
00079 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX)
00080 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNSHIELD|XNTRAPSW)
00081 #define XNTHREAD_SYSTEM_BITS (XNROOT)
00082
00083
00084 #define XNTHREAD_SPARE0 0x10000000
00085 #define XNTHREAD_SPARE1 0x20000000
00086 #define XNTHREAD_SPARE2 0x40000000
00087 #define XNTHREAD_SPARE3 0x80000000
00088 #define XNTHREAD_SPARES 0xf0000000
00089
00090 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00091
00092 #ifdef __RTAI_SIM__
00093 #define XNRUNNING XNTHREAD_SPARE0
00094 #define XNDELETED XNTHREAD_SPARE1
00095 #endif
00096
00097 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
00098
00099 struct xnsched;
00100 struct xnsynch;
00101
00102 typedef void (*xnasr_t)(xnsigmask_t sigs);
00103
00104 typedef struct xnthread {
00105
00106 xnarchtcb_t tcb;
00107
00108 xnflags_t status;
00109
00110 struct xnsched *sched;
00111
00112 xnarch_cpumask_t affinity;
00113
00114 int bprio;
00115
00116 int cprio;
00117
00118 xnholder_t slink;
00119
00120 xnpholder_t rlink;
00121
00122 xnpholder_t plink;
00123
00124 xnholder_t glink;
00125
00126
00127 #define link2thread(laddr,link) \
00128 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00129
00130 xnpqueue_t claimq;
00131
00132 struct xnsynch *wchan;
00133
00134 xntimer_t rtimer;
00135
00136 xntimer_t ptimer;
00137
00138 int poverrun;
00139
00140 xnsigmask_t signals;
00141
00142 xnticks_t rrperiod;
00143
00144 xnticks_t rrcredit;
00145
00146 #ifdef CONFIG_RTAI_OPT_STATS
00147 struct {
00148 unsigned long psw;
00149 unsigned long ssw;
00150 unsigned long csw;
00151
00152 unsigned long pf;
00153 } stat;
00154 #endif
00155
00156 xnasr_t asr;
00157
00158 xnflags_t asrmode;
00159
00160 int asrimask;
00161
00162 unsigned asrlevel;
00163
00164 int imask;
00165
00166 int imode;
00167
00168 int iprio;
00169
00170 unsigned magic;
00171
00172 char name[XNOBJECT_NAME_LEN];
00173
00174 xnticks_t stime;
00175
00176 void (*entry)(void *cookie);
00177
00178 void *cookie;
00179
00180 void *extinfo;
00181
00182 XNARCH_DECL_DISPLAY_CONTEXT();
00183
00184 } xnthread_t;
00185
00186 #define XNHOOK_THREAD_START 1
00187 #define XNHOOK_THREAD_SWITCH 2
00188 #define XNHOOK_THREAD_DELETE 3
00189
00190 typedef struct xnhook {
00191
00192 xnholder_t link;
00193
00194 #define link2hook(laddr) \
00195 ((xnhook_t *)(((char *)laddr) - (int)(&((xnhook_t *)0)->link)))
00196
00197 void (*routine)(xnthread_t *thread);
00198
00199 } xnhook_t;
00200
00201 #define xnthread_name(thread) ((thread)->name)
00202 #define xnthread_sched(thread) ((thread)->sched)
00203 #define xnthread_start_time(thread) ((thread)->stime)
00204 #define xnthread_status_flags(thread) ((thread)->status)
00205 #define xnthread_test_flags(thread,flags) testbits((thread)->status,flags)
00206 #define xnthread_set_flags(thread,flags) __setbits((thread)->status,flags)
00207 #define xnthread_clear_flags(thread,flags) __clrbits((thread)->status,flags)
00208 #define xnthread_initial_priority(thread) ((thread)->iprio)
00209 #define xnthread_base_priority(thread) ((thread)->bprio)
00210 #define xnthread_current_priority(thread) ((thread)->cprio)
00211 #define xnthread_time_slice(thread) ((thread)->rrperiod)
00212 #define xnthread_time_credit(thread) ((thread)->rrcredit)
00213 #define xnthread_archtcb(thread) (&((thread)->tcb))
00214 #define xnthread_asr_level(thread) ((thread)->asrlevel)
00215 #define xnthread_pending_signals(thread) ((thread)->signals)
00216 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
00217 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
00218 #define xnthread_extended_info(thread) ((thread)->extinfo)
00219 #define xnthread_set_magic(thread,m) do { (thread)->magic = (m); } while(0)
00220 #define xnthread_get_magic(thread) ((thread)->magic)
00221 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
00222 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
00223 #define xnthread_user_pid(thread) \
00224 (testbits((thread)->status,XNROOT) || !xnthread_user_task(thread) ? \
00225 0 : xnarch_user_pid(xnthread_archtcb(thread)))
00226
00227 #ifdef CONFIG_RTAI_OPT_STATS
00228 #define xnthread_inc_psw(thread) ++(thread)->stat.psw
00229 #define xnthread_inc_ssw(thread) ++(thread)->stat.ssw
00230 #define xnthread_inc_csw(thread) ++(thread)->stat.csw
00231 #define xnthread_inc_pf(thread) ++(thread)->stat.pf
00232 #else
00233 #define xnthread_inc_psw(thread) do { } while(0)
00234 #define xnthread_inc_ssw(thread) do { } while(0)
00235 #define xnthread_inc_csw(thread) do { } while(0)
00236 #define xnthread_inc_pf(thread) do { } while(0)
00237 #endif
00238
00239 #ifdef __cplusplus
00240 extern "C" {
00241 #endif
00242
00243 int xnthread_init(xnthread_t *thread,
00244 const char *name,
00245 int prio,
00246 xnflags_t flags,
00247 unsigned stacksize);
00248
00249 void xnthread_cleanup_tcb(xnthread_t *thread);
00250
00251 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00252
00253 static inline xnticks_t xnthread_get_timeout(xnthread_t *thread, xnticks_t now)
00254 {
00255 xnticks_t timeout;
00256
00257 if (!testbits(thread->status,XNDELAY))
00258 return 0LL;
00259
00260 timeout = (xntimer_get_date(&thread->rtimer) ? : xntimer_get_date(&thread->ptimer));
00261
00262 if (timeout <= now)
00263 return 1;
00264
00265 return timeout - now;
00266 }
00267
00268 #ifdef __cplusplus
00269 }
00270 #endif
00271
00272 #endif
00273
00274 #endif