thread.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * Xenomai is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * Xenomai 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 Xenomai; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * As a special exception, the RTAI project gives permission
00019  * for additional uses of the text contained in its release of
00020  * Xenomai.
00021  *
00022  * The exception is that, if you link the Xenomai libraries with other
00023  * files to produce an executable, this does not by itself cause the
00024  * resulting executable to be covered by the GNU General Public License.
00025  * Your use of that executable is in no way restricted on account of
00026  * linking the Xenomai libraries code into it.
00027  *
00028  * This exception does not however invalidate any other reasons why
00029  * the executable file might be covered by the GNU General Public
00030  * License.
00031  *
00032  * This exception applies only to the code released by the
00033  * RTAI project under the name Xenomai.  If you copy code from other
00034  * RTAI project releases into a copy of Xenomai, as the General Public
00035  * License permits, the exception does not apply to the code that you
00036  * add in this way.  To avoid misleading anyone as to the status of
00037  * such modified files, you must delete this exception notice from
00038  * them.
00039  *
00040  * If you write modifications of your own for Xenomai, it is your
00041  * choice whether to permit this exception to apply to your
00042  * modifications. If you do not wish that, delete this exception
00043  * notice.
00044  */
00045 
00046 #ifndef _RTAI_NUCLEUS_THREAD_H
00047 #define _RTAI_NUCLEUS_THREAD_H
00048 
00049 #include <nucleus/timer.h>
00050 
00051 /* Status flags */
00052 #define XNSUSP    0x00000001    /* Suspended */
00053 #define XNPEND    0x00000002    /* Sleep-wait for a resource */
00054 #define XNDELAY   0x00000004    /* Delayed */
00055 #define XNREADY   0x00000008    /* Linked to the ready queue */
00056 #define XNDORMANT 0x00000010    /* Not started yet or killed */
00057 #define XNZOMBIE  0x00000020    /* Self-deleting running thread */
00058 #define XNRESTART 0x00000040    /* Restarting thread */
00059 #define XNSTARTED 0x00000080    /* Could be restarted */
00060 #define XNRELAX   0x00000100    /* Relaxed shadow thread (blocking bit) */
00061 
00062 #define XNTIMEO   0x00000200    /* Woken up due to a timeout condition */
00063 #define XNRMID    0x00000400    /* Pending on a removed resource */
00064 #define XNBREAK   0x00000800    /* Forcibly awaken from a wait state */
00065 #define XNKICKED  0x00001000    /* Kicked upon signal (shadow only) */
00066 #define XNBOOST   0x00002000    /* Undergoes regular PIP boost */
00067 
00068 /* Mode flags. */
00069 #define XNLOCK    0x00004000    /* Not preemptable */
00070 #define XNRRB     0x00008000    /* Undergoes a round-robin scheduling */
00071 #define XNASDI    0x00010000    /* ASR are disabled */
00072 
00073 #define XNFPU     0x00020000    /* Thread uses FPU */
00074 #define XNSHADOW  0x00040000    /* Shadow thread */
00075 #define XNROOT    0x00080000    /* Root thread (i.e. Linux/IDLE) */
00076 
00077 /* Must follow the above bits declaration order. */
00078 #define XNTHREAD_SLABEL_INIT \
00079 { "ssp", "pnd", "dly", "rdy", "dor", \
00080   "zom", "rst", "sta", "rlx", "tmo", \
00081   "rmi", "brk", "sig", "bst", "lck", \
00082   "rrb", "asd", "fpu", "usr", "idl" }
00083 
00084 #define XNTHREAD_BLOCK_BITS   (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX)
00085 #define XNTHREAD_MODE_BITS    (XNLOCK|XNRRB|XNASDI)
00086 #define XNTHREAD_SYSTEM_BITS  (XNROOT)
00087 
00088 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00089 
00090 /* These flags are available to the real-time interfaces */
00091 #define XNTHREAD_SPARE0  0x10000000
00092 #define XNTHREAD_SPARE1  0x20000000
00093 #define XNTHREAD_SPARE2  0x40000000
00094 #define XNTHREAD_SPARE3  0x80000000
00095 #define XNTHREAD_SPARES  0xf0000000
00096 
00097 #define XNRUNNING  XNTHREAD_SPARE0      /* Pseudo-status (must not conflict with system bits) */
00098 #define XNDELETED  XNTHREAD_SPARE1      /* idem. */
00099 
00100 #define XNTHREAD_INVALID_ASR  ((void (*)(xnsigmask_t))0)
00101 
00102 struct xnsched;
00103 struct xnsynch;
00104 
00105 typedef void (*xnasr_t)(xnsigmask_t sigs);
00106 
00107 typedef struct xnthread {
00108 
00109     xnarchtcb_t tcb;            /* Architecture-dependent block -- Must be first */
00110 
00111     xnflags_t status;           /* Thread status flags */
00112 
00113     struct xnsched *sched;      /* Thread scheduler */
00114 
00115     xnarch_cpumask_t affinity;  /* Processor affinity. */
00116 
00117     int bprio;                  /* Base priority (before PIP boost) */
00118 
00119     int cprio;                  /* Current priority */
00120 
00121     xnholder_t slink;           /* Thread holder in suspend queue */
00122 
00123     xnpholder_t rlink;          /* Thread holder in ready queue */
00124 
00125     xnpholder_t plink;          /* Thread holder in synchronization queue(s) */
00126 
00127     xnholder_t glink;           /* Thread holder in global queue */
00128 
00129 /* We don't want side-effects on laddr here! */
00130 #define link2thread(laddr,link) \
00131 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00132 
00133     xnpqueue_t claimq;          /* Owned resources claimed by others (PIP) */
00134 
00135     struct xnsynch *wchan;      /* Resource the thread pends on */
00136 
00137     xntimer_t rtimer;           /* Resource timer */
00138 
00139     xntimer_t atimer;           /* Asynchronous timer (shadow only) */
00140 
00141     xntimer_t ptimer;           /* Periodic timer */
00142 
00143     int poverrun;               /* Periodic timer overrun. */
00144 
00145     xnsigmask_t signals;        /* Pending signals */
00146 
00147     xnticks_t rrperiod;         /* Allotted round-robin period (ticks) */
00148 
00149     xnticks_t rrcredit;         /* Remaining round-robin time credit (ticks) */
00150 
00151     xnasr_t asr;                /* Asynchronous service routine */
00152 
00153     xnflags_t asrmode;          /* Thread's mode for ASR */
00154 
00155     int asrimask;               /* Thread's interrupt mask for ASR */
00156 
00157     unsigned asrlevel;          /* ASR execution level (ASRs are reentrant) */
00158 
00159     int imask;                  /* Initial interrupt mask */
00160 
00161     int imode;                  /* Initial mode */
00162 
00163     int iprio;                  /* Initial priority */
00164 
00165     unsigned magic;             /* Skin magic. */
00166 
00167     char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
00168 
00169     xnticks_t stime;            /* Start time */
00170 
00171     void (*entry)(void *cookie); /* Thread entry routine */
00172 
00173     void *cookie;               /* Cookie to pass to the entry routine */
00174 
00175     void *extinfo;              /* Extended information -- user-defined */
00176 
00177     XNARCH_DECL_DISPLAY_CONTEXT();
00178 
00179 } xnthread_t;
00180 
00181 #define XNHOOK_THREAD_START  1
00182 #define XNHOOK_THREAD_SWITCH 2
00183 #define XNHOOK_THREAD_DELETE 3
00184 
00185 typedef struct xnhook {
00186 
00187     xnholder_t link;
00188 
00189 #define link2hook(laddr) \
00190 ((xnhook_t *)(((char *)laddr) - (int)(&((xnhook_t *)0)->link)))
00191 
00192     void (*routine)(xnthread_t *thread);
00193 
00194 } xnhook_t;
00195 
00196 #define xnthread_name(thread)              ((thread)->name)
00197 #define xnthread_sched(thread)             ((thread)->sched)
00198 #define xnthread_start_time(thread)        ((thread)->stime)
00199 #define xnthread_status_flags(thread)      ((thread)->status)
00200 #define xnthread_test_flags(thread,flags)  testbits((thread)->status,flags)
00201 #define xnthread_set_flags(thread,flags)   __setbits((thread)->status,flags)
00202 #define xnthread_clear_flags(thread,flags) __clrbits((thread)->status,flags)
00203 #define xnthread_initial_priority(thread)  ((thread)->iprio)
00204 #define xnthread_base_priority(thread)     ((thread)->bprio)
00205 #define xnthread_current_priority(thread)  ((thread)->cprio)
00206 #define xnthread_time_slice(thread)        ((thread)->rrperiod)
00207 #define xnthread_time_credit(thread)       ((thread)->rrcredit)
00208 #define xnthread_archtcb(thread)           (&((thread)->tcb))
00209 #define xnthread_asr_level(thread)         ((thread)->asrlevel)
00210 #define xnthread_pending_signals(thread)   ((thread)->signals)
00211 #define xnthread_timeout(thread)           xntimer_get_timeout(&(thread)->rtimer)
00212 #define xnthread_stack_size(thread)        xnarch_stack_size(xnthread_archtcb(thread))
00213 #define xnthread_extended_info(thread)     ((thread)->extinfo)
00214 #define xnthread_set_magic(thread,m)       do { (thread)->magic = (m); } while(0)
00215 #define xnthread_get_magic(thread)         ((thread)->magic)
00216 #define xnthread_signaled_p(thread)        ((thread)->signals != 0)
00217 
00218 #ifdef __cplusplus
00219 extern "C" {
00220 #endif
00221 
00222 int xnthread_init(xnthread_t *thread,
00223                   const char *name,
00224                   int prio,
00225                   xnflags_t flags,
00226                   unsigned stacksize);
00227 
00228 void xnthread_cleanup_tcb(xnthread_t *thread);
00229 
00230 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00231 
00232 #ifdef __cplusplus
00233 }
00234 #endif
00235 
00236 #endif /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00237 
00238 #endif /* !_RTAI_NUCLEUS_THREAD_H */

Generated on Mon Dec 13 09:49:49 2004 for RTAI API by  doxygen 1.3.9.1