thread.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * RTAI/fusion is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * RTAI/fusion is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with RTAI/fusion; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA.
00018  */
00019 
00020 #ifndef _RTAI_NUCLEUS_THREAD_H
00021 #define _RTAI_NUCLEUS_THREAD_H
00022 
00023 #include <nucleus/timer.h>
00024 
00025 /* Status flags */
00026 #define XNSUSP    0x00000001    /* Suspended */
00027 #define XNPEND    0x00000002    /* Sleep-wait for a resource */
00028 #define XNDELAY   0x00000004    /* Delayed */
00029 #define XNREADY   0x00000008    /* Linked to the ready queue */
00030 #define XNDORMANT 0x00000010    /* Not started yet or killed */
00031 #define XNZOMBIE  0x00000020    /* Zombie thread in deletion process */
00032 #define XNRESTART 0x00000040    /* Restarting thread */
00033 #define XNSTARTED 0x00000080    /* Could be restarted */
00034 #define XNRELAX   0x00000100    /* Relaxed shadow thread (blocking bit) */
00035 
00036 #define XNTIMEO   0x00000200    /* Woken up due to a timeout condition */
00037 #define XNRMID    0x00000400    /* Pending on a removed resource */
00038 #define XNBREAK   0x00000800    /* Forcibly awaken from a wait state */
00039 #define XNKICKED  0x00001000    /* Kicked upon signal (shadow only) */
00040 #define XNBOOST   0x00002000    /* Undergoes regular PIP boost */
00041 
00042 /* Mode flags. */
00043 #define XNLOCK    0x00004000    /* Not preemptible */
00044 #define XNRRB     0x00008000    /* Undergoes a round-robin scheduling */
00045 #define XNASDI    0x00010000    /* ASR are disabled */
00046 #define XNSHIELD  0x00020000    /* IRQ shield is enabled (shadow only) */
00047 #define XNTRAPSW  0x00040000    /* Trap execution mode switches */
00048 
00049 #define XNFPU     0x00080000    /* Thread uses FPU */
00050 #define XNSHADOW  0x00100000    /* Shadow thread */
00051 #define XNROOT    0x00200000    /* Root thread (i.e. Linux/IDLE) */
00052 
00053 /* Must follow the declaration order of the above bits. */
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 /* These flags are available to the real-time interfaces */
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      /* Pseudo-status (must not conflict with system bits) */
00077 #define XNDELETED  XNTHREAD_SPARE1      /* idem. */
00078 #endif /* __RTAI_SIM__ */
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;            /* Architecture-dependent block -- Must be first */
00090 
00091     xnflags_t status;           /* Thread status flags */
00092 
00093     struct xnsched *sched;      /* Thread scheduler */
00094 
00095     xnarch_cpumask_t affinity;  /* Processor affinity. */
00096 
00097     int bprio;                  /* Base priority (before PIP boost) */
00098 
00099     int cprio;                  /* Current priority */
00100 
00101     xnholder_t slink;           /* Thread holder in suspend queue */
00102 
00103     xnpholder_t rlink;          /* Thread holder in ready queue */
00104 
00105     xnpholder_t plink;          /* Thread holder in synchronization queue(s) */
00106 
00107     xnholder_t glink;           /* Thread holder in global queue */
00108 
00109 /* We don't want side-effects on laddr here! */
00110 #define link2thread(laddr,link) \
00111 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00112 
00113     xnpqueue_t claimq;          /* Owned resources claimed by others (PIP) */
00114 
00115     struct xnsynch *wchan;      /* Resource the thread pends on */
00116 
00117     xntimer_t rtimer;           /* Resource timer */
00118 
00119     xntimer_t ptimer;           /* Periodic timer */
00120 
00121     int poverrun;               /* Periodic timer overrun. */
00122 
00123     xnsigmask_t signals;        /* Pending signals */
00124 
00125     xnticks_t rrperiod;         /* Allotted round-robin period (ticks) */
00126 
00127     xnticks_t rrcredit;         /* Remaining round-robin time credit (ticks) */
00128 
00129     struct {
00130 
00131         unsigned long psw;      /* Primary mode switch count */
00132         unsigned long ssw;      /* Secondary mode switch count */
00133         unsigned long pf;       /* Number of page faults */
00134 
00135     } stat;
00136 
00137     xnasr_t asr;                /* Asynchronous service routine */
00138 
00139     xnflags_t asrmode;          /* Thread's mode for ASR */
00140 
00141     int asrimask;               /* Thread's interrupt mask for ASR */
00142 
00143     unsigned asrlevel;          /* ASR execution level (ASRs are reentrant) */
00144 
00145     int imask;                  /* Initial interrupt mask */
00146 
00147     int imode;                  /* Initial mode */
00148 
00149     int iprio;                  /* Initial priority */
00150 
00151     unsigned magic;             /* Skin magic. */
00152 
00153     char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
00154 
00155     xnticks_t stime;            /* Start time */
00156 
00157     void (*entry)(void *cookie); /* Thread entry routine */
00158 
00159     void *cookie;               /* Cookie to pass to the entry routine */
00160 
00161     void *extinfo;              /* Extended information -- user-defined */
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 /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00224 
00225 #endif /* !_RTAI_NUCLEUS_THREAD_H */

Generated on Wed Jun 22 22:54:02 2005 for RTAI Fusion API by  doxygen 1.4.1