22 #ifndef _XENO_NUCLEUS_THREAD_H
23 #define _XENO_NUCLEUS_THREAD_H
25 #include <nucleus/types.h>
35 #define XNSUSP 0x00000001
36 #define XNPEND 0x00000002
37 #define XNDELAY 0x00000004
38 #define XNREADY 0x00000008
39 #define XNDORMANT 0x00000010
40 #define XNZOMBIE 0x00000020
41 #define XNRESTART 0x00000040
42 #define XNSTARTED 0x00000080
43 #define XNMAPPED 0x00000100
44 #define XNRELAX 0x00000200
45 #define XNMIGRATE 0x00000400
46 #define XNHELD 0x00000800
48 #define XNBOOST 0x00001000
49 #define XNDEBUG 0x00002000
50 #define XNLOCK 0x00004000
51 #define XNRRB 0x00008000
52 #define XNASDI 0x00010000
53 #define XNDEFCAN 0x00020000
60 #define XNTRAPSW 0x00040000
61 #define XNRPIOFF 0x00080000
62 #define XNFPU 0x00100000
63 #define XNSHADOW 0x00200000
64 #define XNROOT 0x00400000
65 #define XNOTHER 0x00800000
88 #define XNTHREAD_STATE_LABELS "SWDRU....X.HbTlr..tof.."
90 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNMIGRATE|XNHELD)
91 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNTRAPSW|XNRPIOFF)
94 #define XNTHREAD_STATE_SPARE0 0x10000000
95 #define XNTHREAD_STATE_SPARE1 0x20000000
96 #define XNTHREAD_STATE_SPARE2 0x40000000
97 #define XNTHREAD_STATE_SPARE3 0x80000000
98 #define XNTHREAD_STATE_SPARES 0xf0000000
108 #define XNTIMEO 0x00000001
109 #define XNRMID 0x00000002
110 #define XNBREAK 0x00000004
111 #define XNKICKED 0x00000008
112 #define XNWAKEN 0x00000010
113 #define XNROBBED 0x00000020
114 #define XNATOMIC 0x00000040
115 #define XNAFFSET 0x00000080
116 #define XNPRIOSET 0x00000100
117 #define XNABORT 0x00000200
118 #define XNCANPND 0x00000400
119 #define XNAMOK 0x00000800
120 #define XNSWREP 0x00001000
123 #define XNTHREAD_INFO_SPARE0 0x10000000
124 #define XNTHREAD_INFO_SPARE1 0x20000000
125 #define XNTHREAD_INFO_SPARE2 0x40000000
126 #define XNTHREAD_INFO_SPARE3 0x80000000
127 #define XNTHREAD_INFO_SPARES 0xf0000000
156 #if defined(__KERNEL__) || defined(__XENO_SIM__)
158 #include <nucleus/stat.h>
161 #include <nucleus/schedparam.h>
165 #define XNRUNNING XNTHREAD_STATE_SPARE0
166 #define XNDELETED XNTHREAD_STATE_SPARE1
169 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
175 struct xnsched_class;
176 struct xnsched_tpslot;
177 union xnsched_policy_param;
180 struct xnthread_operations {
181 int (*get_denormalized_prio)(
struct xnthread *,
int coreprio);
182 unsigned (*get_magic)(void);
185 struct xnthread_init_attr {
186 struct xntbase *tbase;
187 struct xnthread_operations *ops;
189 unsigned int stacksize;
193 struct xnthread_start_attr {
196 xnarch_cpumask_t affinity;
197 void (*entry)(
void *cookie);
201 struct xnthread_wait_context {
202 unsigned long oldstate;
205 typedef void (*xnasr_t)(xnsigmask_t sigs);
207 typedef struct xnthread {
217 struct xnsched_class *sched_class;
219 struct xnsched_class *base_class;
221 #ifdef CONFIG_XENO_OPT_SCHED_TP
222 struct xnsched_tpslot *tps;
223 struct xnholder tp_link;
225 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
226 struct xnsched_sporadic_data *pss;
231 xnarch_cpumask_t affinity;
243 #ifdef CONFIG_XENO_OPT_PRIOCPL
251 #define link2thread(ln, fld) container_of(ln, struct xnthread, fld)
255 struct xnsynch *wchan;
257 struct xnsynch *wwake;
286 struct xnthread_wait_context *wcontext;
289 xnstat_counter_t ssw;
290 xnstat_counter_t csw;
292 xnstat_exectime_t account;
293 xnstat_exectime_t lastperiod;
296 #ifdef CONFIG_XENO_OPT_SELECT
297 struct xnselector *selector;
314 struct xnsched_class *init_class;
316 union xnsched_policy_param init_schedparam;
323 struct xnthread_operations *ops;
325 char name[XNOBJECT_NAME_LEN];
327 void (*entry)(
void *cookie);
331 #ifdef CONFIG_XENO_OPT_PERVASIVE
332 unsigned long *u_mode;
335 XNARCH_DECL_DISPLAY_CONTEXT();
339 #define XNHOOK_THREAD_START 1
340 #define XNHOOK_THREAD_SWITCH 2
341 #define XNHOOK_THREAD_DELETE 3
343 typedef struct xnhook {
345 #define link2hook(ln) container_of(ln, xnhook_t, link)
346 void (*routine)(
struct xnthread *thread);
349 #define xnthread_name(thread) ((thread)->name)
350 #define xnthread_clear_name(thread) do { *(thread)->name = 0; } while(0)
351 #define xnthread_sched(thread) ((thread)->sched)
352 #define xnthread_start_time(thread) ((thread)->stime)
353 #define xnthread_state_flags(thread) ((thread)->state)
354 #define xnthread_test_state(thread,flags) testbits((thread)->state,flags)
355 #define xnthread_set_state(thread,flags) __setbits((thread)->state,flags)
356 #define xnthread_clear_state(thread,flags) __clrbits((thread)->state,flags)
357 #define xnthread_test_info(thread,flags) testbits((thread)->info,flags)
358 #define xnthread_set_info(thread,flags) __setbits((thread)->info,flags)
359 #define xnthread_clear_info(thread,flags) __clrbits((thread)->info,flags)
360 #define xnthread_lock_count(thread) ((thread)->schedlck)
361 #define xnthread_init_schedparam(thread) ((thread)->init_schedparam)
362 #define xnthread_base_priority(thread) ((thread)->bprio)
363 #define xnthread_current_priority(thread) ((thread)->cprio)
364 #define xnthread_init_class(thread) ((thread)->init_class)
365 #define xnthread_base_class(thread) ((thread)->base_class)
366 #define xnthread_sched_class(thread) ((thread)->sched_class)
367 #define xnthread_time_slice(thread) ((thread)->rrperiod)
368 #define xnthread_time_credit(thread) ((thread)->rrcredit)
369 #define xnthread_archtcb(thread) (&((thread)->tcb))
370 #define xnthread_asr_level(thread) ((thread)->asrlevel)
371 #define xnthread_pending_signals(thread) ((thread)->signals)
372 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
373 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
374 #define xnthread_stack_base(thread) xnarch_stack_base(xnthread_archtcb(thread))
375 #define xnthread_stack_end(thread) xnarch_stack_end(xnthread_archtcb(thread))
376 #define xnthread_handle(thread) ((thread)->registry.handle)
377 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
378 #define xnthread_time_base(thread) ((thread)->rtimer.base)
380 #define xnthread_time_base(thread) (&nktbase)
382 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
383 #define xnthread_timed_p(thread) (!!testbits(xnthread_time_base(thread)->status, XNTBRUN))
384 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
385 #define xnthread_user_pid(thread) \
386 (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
387 0 : xnarch_user_pid(xnthread_archtcb(thread)))
388 #define xnthread_affinity(thread) ((thread)->affinity)
389 #define xnthread_affine_p(thread, cpu) xnarch_cpu_isset(cpu, (thread)->affinity)
390 #define xnthread_get_exectime(thread) xnstat_exectime_get_total(&(thread)->stat.account)
391 #define xnthread_get_lastswitch(thread) xnstat_exectime_get_last_switch((thread)->sched)
392 #ifdef CONFIG_XENO_OPT_PERVASIVE
393 #define xnthread_inc_rescnt(thread) ({ (thread)->hrescnt++; })
394 #define xnthread_dec_rescnt(thread) ({ --(thread)->hrescnt; })
395 #define xnthread_get_rescnt(thread) ((thread)->hrescnt)
397 #define xnthread_inc_rescnt(thread) do { } while (0)
398 #define xnthread_dec_rescnt(thread) do { } while (0)
400 #if defined(CONFIG_XENO_OPT_WATCHDOG) || defined(CONFIG_XENO_SKIN_POSIX)
401 #define xnthread_amok_p(thread) xnthread_test_info(thread, XNAMOK)
402 #define xnthread_clear_amok(thread) xnthread_clear_info(thread, XNAMOK)
404 #define xnthread_amok_p(thread) ({ (void)(thread); 0; })
405 #define xnthread_clear_amok(thread) do { (void)(thread); } while (0)
409 static inline int xnthread_get_denormalized_prio(
struct xnthread *t,
int coreprio)
411 return t->ops && t->ops->get_denormalized_prio
412 ? t->ops->get_denormalized_prio(t, coreprio) : coreprio;
415 static inline unsigned xnthread_get_magic(
struct xnthread *t)
417 return t->ops ? t->ops->get_magic() : 0;
421 struct xnthread_wait_context *xnthread_get_wait_context(
struct xnthread *thread)
423 return thread->wcontext;
427 int xnthread_register(
struct xnthread *thread,
const char *name)
433 struct xnthread *xnthread_lookup(xnhandle_t threadh)
435 struct xnthread *thread = (
struct xnthread *)xnregistry_lookup(threadh);
436 return (thread && xnthread_handle(thread) == threadh) ? thread : NULL;
443 int xnthread_init(
struct xnthread *thread,
444 const struct xnthread_init_attr *attr,
446 struct xnsched_class *sched_class,
447 const union xnsched_policy_param *sched_param);
449 void xnthread_cleanup_tcb(
struct xnthread *thread);
451 char *xnthread_format_status(xnflags_t status,
char *buf,
int size);
453 int *xnthread_get_errno_location(
struct xnthread *thread);
455 xnticks_t xnthread_get_timeout(
struct xnthread *thread, xnticks_t tsc_ns);
457 xnticks_t xnthread_get_period(
struct xnthread *thread);
459 void xnthread_prepare_wait(
struct xnthread_wait_context *wc);
461 void xnthread_finish_wait(
struct xnthread_wait_context *wc,
462 void (*cleanup)(
struct xnthread_wait_context *wc));