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', 'f', \
00085 '.', '.', '.', \
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
00113
00114 #define XNTHREAD_INFO_SPARE0 0x10000000
00115 #define XNTHREAD_INFO_SPARE1 0x20000000
00116 #define XNTHREAD_INFO_SPARE2 0x40000000
00117 #define XNTHREAD_INFO_SPARE3 0x80000000
00118 #define XNTHREAD_INFO_SPARES 0xf0000000
00119
00121
00122 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00123
00124 #include <nucleus/stat.h>
00125
00126 #ifdef __XENO_SIM__
00127
00128 #define XNRUNNING XNTHREAD_STATE_SPARE0
00129 #define XNDELETED XNTHREAD_STATE_SPARE1
00130 #endif
00131
00132 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
00133
00134 struct xnsched;
00135 struct xnsynch;
00136
00137 typedef void (*xnasr_t)(xnsigmask_t sigs);
00138
00139 typedef struct xnthread {
00140
00141 xnarchtcb_t tcb;
00142
00143 xnflags_t state;
00144
00145 xnflags_t info;
00146
00147 struct xnsched *sched;
00148
00149 xnarch_cpumask_t affinity;
00150
00151 int bprio;
00152
00153 int cprio;
00154
00155 xnpholder_t rlink;
00156
00157 xnpholder_t plink;
00158
00159 xnholder_t glink;
00160
00161
00162 #define link2thread(laddr,link) \
00163 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00164
00165 xnpqueue_t claimq;
00166
00167 struct xnsynch *wchan;
00168
00169 xntimer_t rtimer;
00170
00171 xntimer_t ptimer;
00172
00173 xnticks_t pexpect;
00174
00175 xnsigmask_t signals;
00176
00177 xnticks_t rrperiod;
00178
00179 xnticks_t rrcredit;
00180
00181 struct {
00182 xnstat_counter_t ssw;
00183 xnstat_counter_t csw;
00184 xnstat_counter_t pf;
00185 xnstat_runtime_t account;
00186 } stat;
00187
00188 int errcode;
00189
00190 xnasr_t asr;
00191
00192 xnflags_t asrmode;
00193
00194 int asrimask;
00195
00196 unsigned asrlevel;
00197
00198 int imask;
00199
00200 int imode;
00201
00202 int iprio;
00203
00204 #ifdef CONFIG_XENO_OPT_REGISTRY
00205 struct {
00206 xnhandle_t handle;
00207 const char *waitkey;
00208 } registry;
00209 #endif
00210
00211 unsigned magic;
00212
00213 char name[XNOBJECT_NAME_LEN];
00214
00215 xnticks_t stime;
00216
00217 void (*entry)(void *cookie);
00218
00219 void *cookie;
00220
00221 XNARCH_DECL_DISPLAY_CONTEXT();
00222
00223 } xnthread_t;
00224
00225 #define XNHOOK_THREAD_START 1
00226 #define XNHOOK_THREAD_SWITCH 2
00227 #define XNHOOK_THREAD_DELETE 3
00228
00229 typedef struct xnhook {
00230
00231 xnholder_t link;
00232
00233 #define link2hook(laddr) \
00234 ((xnhook_t *)(((char *)laddr) - (int)(&((xnhook_t *)0)->link)))
00235
00236 void (*routine)(xnthread_t *thread);
00237
00238 } xnhook_t;
00239
00240 #define xnthread_name(thread) ((thread)->name)
00241 #define xnthread_clear_name(thread) do { *(thread)->name = 0; } while(0)
00242 #define xnthread_sched(thread) ((thread)->sched)
00243 #define xnthread_start_time(thread) ((thread)->stime)
00244 #define xnthread_state_flags(thread) ((thread)->state)
00245 #define xnthread_test_state(thread,flags) testbits((thread)->state,flags)
00246 #define xnthread_set_state(thread,flags) __setbits((thread)->state,flags)
00247 #define xnthread_clear_state(thread,flags) __clrbits((thread)->state,flags)
00248 #define xnthread_test_info(thread,flags) testbits((thread)->info,flags)
00249 #define xnthread_set_info(thread,flags) __setbits((thread)->info,flags)
00250 #define xnthread_clear_info(thread,flags) __clrbits((thread)->info,flags)
00251 #define xnthread_initial_priority(thread) ((thread)->iprio)
00252 #define xnthread_base_priority(thread) ((thread)->bprio)
00253 #define xnthread_current_priority(thread) ((thread)->cprio)
00254 #define xnthread_time_slice(thread) ((thread)->rrperiod)
00255 #define xnthread_time_credit(thread) ((thread)->rrcredit)
00256 #define xnthread_archtcb(thread) (&((thread)->tcb))
00257 #define xnthread_asr_level(thread) ((thread)->asrlevel)
00258 #define xnthread_pending_signals(thread) ((thread)->signals)
00259 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
00260 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
00261 #define xnthread_handle(thread) ((thread)->registry.handle)
00262 #define xnthread_set_magic(thread,m) do { (thread)->magic = (m); } while(0)
00263 #define xnthread_get_magic(thread) ((thread)->magic)
00264 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
00265 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
00266 #define xnthread_user_pid(thread) \
00267 (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
00268 0 : xnarch_user_pid(xnthread_archtcb(thread)))
00269
00270 #ifdef __cplusplus
00271 extern "C" {
00272 #endif
00273
00274 int xnthread_init(xnthread_t *thread,
00275 const char *name,
00276 int prio,
00277 xnflags_t flags,
00278 unsigned stacksize);
00279
00280 void xnthread_cleanup_tcb(xnthread_t *thread);
00281
00282 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00283
00284 int *xnthread_get_errno_location(void);
00285
00286 static inline xnticks_t xnthread_get_timeout(xnthread_t *thread, xnticks_t now)
00287 {
00288 xnticks_t timeout;
00289
00290 if (!xnthread_test_state(thread,XNDELAY))
00291 return 0LL;
00292
00293 timeout = (xntimer_get_date(&thread->rtimer) ? : xntimer_get_date(&thread->ptimer));
00294
00295 if (timeout <= now)
00296 return 1;
00297
00298 return timeout - now;
00299 }
00300
00301 static inline xnticks_t xnthread_get_period(xnthread_t *thread)
00302 {
00303 xnticks_t period = 0;
00304
00305
00306
00307
00308
00309
00310
00311
00312 if (xntimer_running_p(&thread->ptimer))
00313 period = xntimer_get_interval(&thread->ptimer);
00314 else if (xnthread_test_state(thread,XNRRB))
00315 period = xnthread_time_slice(thread);
00316
00317 return period;
00318 }
00319
00320 #ifdef __cplusplus
00321 }
00322 #endif
00323
00324 #endif
00325
00326 #endif