00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _XENO_NUCLEUS_THREAD_H
00021 #define _XENO_NUCLEUS_THREAD_H
00022
00023 #include <nucleus/timer.h>
00024
00031
00032
00033 #define XNSUSP 0x00000001
00034 #define XNPEND 0x00000002
00035 #define XNDELAY 0x00000004
00036 #define XNREADY 0x00000008
00037 #define XNDORMANT 0x00000010
00038 #define XNZOMBIE 0x00000020
00039 #define XNRESTART 0x00000040
00040 #define XNSTARTED 0x00000080
00041 #define XNMAPPED 0x00000100
00042 #define XNRELAX 0x00000200
00043 #define XNHELD 0x00000400
00045 #define XNBOOST 0x00000800
00046 #define XNDEBUG 0x00001000
00047 #define XNLOCK 0x00002000
00048 #define XNRRB 0x00004000
00049 #define XNASDI 0x00008000
00050 #define XNSHIELD 0x00010000
00051 #define XNTRAPSW 0x00020000
00052 #define XNRPIOFF 0x00040000
00054 #define XNFPU 0x00100000
00055 #define XNSHADOW 0x00200000
00056 #define XNROOT 0x00400000
00057 #define XNINVPS 0x00800000
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #define XNTHREAD_STATE_LABELS { \
00081 'S', 'W', 'D', 'R', 'U', \
00082 '.', '.', '.', '.', 'X', \
00083 'H', 'b', 'T', 'l', 'r', \
00084 '.', 's', 't', 'o', '.', \
00085 'f', '.', '.', '.', \
00086 }
00087
00088 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNHELD)
00089 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNSHIELD|XNTRAPSW|XNRPIOFF)
00090
00091
00092 #define XNTHREAD_STATE_SPARE0 0x10000000
00093 #define XNTHREAD_STATE_SPARE1 0x20000000
00094 #define XNTHREAD_STATE_SPARE2 0x40000000
00095 #define XNTHREAD_STATE_SPARE3 0x80000000
00096 #define XNTHREAD_STATE_SPARES 0xf0000000
00097
00104
00105
00106 #define XNTIMEO 0x00000001
00107 #define XNRMID 0x00000002
00108 #define XNBREAK 0x00000004
00109 #define XNKICKED 0x00000008
00110 #define XNWAKEN 0x00000010
00111 #define XNROBBED 0x00000020
00112 #define XNATOMIC 0x00000040
00114
00115 #define XNTHREAD_INFO_SPARE0 0x10000000
00116 #define XNTHREAD_INFO_SPARE1 0x20000000
00117 #define XNTHREAD_INFO_SPARE2 0x40000000
00118 #define XNTHREAD_INFO_SPARE3 0x80000000
00119 #define XNTHREAD_INFO_SPARES 0xf0000000
00120
00122
00123 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00124
00125 #include <nucleus/stat.h>
00126
00127 #ifdef __XENO_SIM__
00128
00129 #define XNRUNNING XNTHREAD_STATE_SPARE0
00130 #define XNDELETED XNTHREAD_STATE_SPARE1
00131 #endif
00132
00133 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
00134
00135 struct xnsched;
00136 struct xnsynch;
00137 struct xnrpi;
00138
00139 typedef void (*xnasr_t)(xnsigmask_t sigs);
00140
00141 typedef struct xnthread {
00142
00143 xnarchtcb_t tcb;
00144
00145 xnflags_t state;
00146
00147 xnflags_t info;
00148
00149 struct xnsched *sched;
00150
00151 xnarch_cpumask_t affinity;
00152
00153 int bprio;
00154
00155 int cprio;
00156
00157 u_long schedlck;
00159 xnpholder_t rlink;
00160
00161 xnpholder_t plink;
00162
00163 #if !defined(CONFIG_XENO_OPT_RPIDISABLE) && defined(CONFIG_XENO_OPT_PERVASIVE)
00164 xnpholder_t xlink;
00165
00166 struct xnrpi *rpi;
00167 #endif
00168
00169 xnholder_t glink;
00170
00171 #define link2thread(ln, fld) container_of(ln, xnthread_t, fld)
00172
00173 xnpqueue_t claimq;
00174
00175 struct xnsynch *wchan;
00176
00177 xntimer_t rtimer;
00178
00179 xntimer_t ptimer;
00180
00181 xnticks_t pexpect;
00182
00183 xnsigmask_t signals;
00184
00185 xnticks_t rrperiod;
00186
00187 xnticks_t rrcredit;
00188
00189 struct {
00190 xnstat_counter_t ssw;
00191 xnstat_counter_t csw;
00192 xnstat_counter_t pf;
00193 xnstat_runtime_t account;
00194 } stat;
00195
00196 int errcode;
00197
00198 xnasr_t asr;
00199
00200 xnflags_t asrmode;
00201
00202 int asrimask;
00203
00204 unsigned asrlevel;
00205
00206 int imask;
00207
00208 int imode;
00209
00210 int iprio;
00211
00212 #ifdef CONFIG_XENO_OPT_REGISTRY
00213 struct {
00214 xnhandle_t handle;
00215 const char *waitkey;
00216 } registry;
00217 #endif
00218
00219 unsigned magic;
00220
00221 char name[XNOBJECT_NAME_LEN];
00222
00223 xnticks_t stime;
00224
00225 void (*entry)(void *cookie);
00226
00227 void *cookie;
00228
00229 XNARCH_DECL_DISPLAY_CONTEXT();
00230
00231 } xnthread_t;
00232
00233 #define XNHOOK_THREAD_START 1
00234 #define XNHOOK_THREAD_SWITCH 2
00235 #define XNHOOK_THREAD_DELETE 3
00236
00237 typedef struct xnhook {
00238
00239 xnholder_t link;
00240
00241 #define link2hook(ln) container_of(ln, xnhook_t, link)
00242
00243 void (*routine)(xnthread_t *thread);
00244
00245 } xnhook_t;
00246
00247 #define xnthread_name(thread) ((thread)->name)
00248 #define xnthread_clear_name(thread) do { *(thread)->name = 0; } while(0)
00249 #define xnthread_sched(thread) ((thread)->sched)
00250 #define xnthread_start_time(thread) ((thread)->stime)
00251 #define xnthread_state_flags(thread) ((thread)->state)
00252 #define xnthread_test_state(thread,flags) testbits((thread)->state,flags)
00253 #define xnthread_set_state(thread,flags) __setbits((thread)->state,flags)
00254 #define xnthread_clear_state(thread,flags) __clrbits((thread)->state,flags)
00255 #define xnthread_test_info(thread,flags) testbits((thread)->info,flags)
00256 #define xnthread_set_info(thread,flags) __setbits((thread)->info,flags)
00257 #define xnthread_clear_info(thread,flags) __clrbits((thread)->info,flags)
00258 #define xnthread_lock_count(thread) ((thread)->schedlck)
00259 #define xnthread_initial_priority(thread) ((thread)->iprio)
00260 #define xnthread_base_priority(thread) ((thread)->bprio)
00261 #define xnthread_current_priority(thread) ((thread)->cprio)
00262 #define xnthread_time_slice(thread) ((thread)->rrperiod)
00263 #define xnthread_time_credit(thread) ((thread)->rrcredit)
00264 #define xnthread_archtcb(thread) (&((thread)->tcb))
00265 #define xnthread_asr_level(thread) ((thread)->asrlevel)
00266 #define xnthread_pending_signals(thread) ((thread)->signals)
00267 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
00268 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
00269 #define xnthread_handle(thread) ((thread)->registry.handle)
00270 #define xnthread_set_magic(thread,m) do { (thread)->magic = (m); } while(0)
00271 #define xnthread_get_magic(thread) ((thread)->magic)
00272 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
00273 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
00274 #define xnthread_user_pid(thread) \
00275 (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
00276 0 : xnarch_user_pid(xnthread_archtcb(thread)))
00277
00278 #ifdef __cplusplus
00279 extern "C" {
00280 #endif
00281
00282 int xnthread_init(xnthread_t *thread,
00283 const char *name,
00284 int prio,
00285 xnflags_t flags,
00286 unsigned stacksize);
00287
00288 void xnthread_cleanup_tcb(xnthread_t *thread);
00289
00290 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00291
00292 int *xnthread_get_errno_location(void);
00293
00294 static inline xnticks_t xnthread_get_timeout(xnthread_t *thread, xnticks_t now)
00295 {
00296 xnticks_t timeout;
00297
00298 if (!xnthread_test_state(thread,XNDELAY))
00299 return 0LL;
00300
00301 timeout = (xntimer_get_date(&thread->rtimer) ? : xntimer_get_date(&thread->ptimer));
00302
00303 if (timeout <= now)
00304 return 1;
00305
00306 return timeout - now;
00307 }
00308
00309 static inline xnticks_t xnthread_get_period(xnthread_t *thread)
00310 {
00311 xnticks_t period = 0;
00312
00313
00314
00315
00316
00317
00318
00319
00320 if (xntimer_running_p(&thread->ptimer))
00321 period = xntimer_get_interval(&thread->ptimer);
00322 else if (xnthread_test_state(thread,XNRRB))
00323 period = xnthread_time_slice(thread);
00324
00325 return period;
00326 }
00327
00328 #ifdef __cplusplus
00329 }
00330 #endif
00331
00332 #endif
00333
00334 #endif