rtai-core/include/xenomai/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 _xenomai_thread_h
00047 #define _xenomai_thread_h
00048 
00049 #include "xenomai/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    /* In startable state */
00057 #define XNWMUTEX  0x00000020    /* Ready-wait for a kernel mutex */
00058 #define XNFROZEN  0x00000040    /* Frozen by debugger */
00059 #define XNZOMBIE  0x00000080    /* Self-deleting running thread */
00060 #define XNRESTART 0x00000100    /* Restarting thread */
00061 #define XNSTARTED 0x00000200    /* Can be restarted */
00062 #define XNRELAX   0x00000400    /* Relaxed scheduling mode (a blocking bit) */
00063 #define XNAUTOSW  0x00000800    /* Auto-switch to RTAI on return from Linux */
00064 
00065 #define XNTIMEO   0x00001000    /* Woken up due to a timeout condition */
00066 #define XNRMID    0x00002000    /* Pending on a removed resource */
00067 #define XNBREAK   0x00004000    /* Forcibly woken up from a wait state */
00068 #define XNBOOST   0x00008000    /* Undergoes regular PIP boost */
00069 #define XNSYSSW   0x00010000    /* Migration due to syscall handling */
00070 
00071 /* Mode flags. */
00072 #define XNLOCK    0x00020000    /* Not preemptable */
00073 #define XNRRB     0x00040000    /* Undergoes a round-robin scheduling */
00074 #define XNASDI    0x00080000    /* ASR are disabled */
00075 
00076 #define XNFPU     0x00100000    /* Thread uses FPU */
00077 #define XNISVC    0x00200000    /* Interrupt svc thread -- Don't freeze */
00078 #define XNSHADOW  0x00400000    /* Shadow thread */
00079 #define XNROOT    0x00800000    /* Root thread (i.e. Linux/IDLE) */
00080 
00081 #define XNTHREAD_BLOCK_BITS  (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNFROZEN|XNRELAX)
00082 #define XNTHREAD_MODE_BITS   (XNLOCK|XNRRB|XNASDI)
00083 #define XNTHREAD_SYSTEM_BITS (XNISVC|XNROOT)
00084 
00085 /* These flags are available to the real-time interfaces */
00086 #define XNTHREAD_SPARE0  0x10000000
00087 #define XNTHREAD_SPARE1  0x20000000
00088 #define XNTHREAD_SPARE2  0x40000000
00089 #define XNTHREAD_SPARE3  0x80000000
00090 
00091 #define XNRUNNING  XNTHREAD_SPARE0      /* Pseudo-status (must not conflict with system bits) */
00092 #define XNDELETED  XNTHREAD_SPARE1      /* idem. */
00093 
00094 #define XNTHREAD_INVALID_ASR  ((void (*)(xnsigmask_t))0)
00095 
00096 #define XNTHREAD_SHADOW_SIGKILL  0x1
00097 
00098 struct xnsched;
00099 struct xnsynch;
00100 struct xnmutex;
00101 
00102 typedef void (*xnasr_t)(xnsigmask_t sigs);
00103 
00104 typedef struct xnthread {
00105 
00106     xnarchtcb_t tcb;            /* Architecture-dependent block -- Must be first */
00107 
00108     xnflags_t status;           /* Thread status flags */
00109 
00110     struct xnsched *sched;      /* Thread scheduler */
00111 
00112     int bprio;                  /* Base priority (before PIP boost) */
00113 
00114     int cprio;                  /* Current priority */
00115 
00116     unsigned magic;             /* Skin magic. */
00117 
00118     char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
00119 
00120     xnticks_t rrperiod;         /* Allotted round-robin period (ticks) */
00121 
00122     xnticks_t rrcredit;         /* Remaining round-robin time credit (ticks) */
00123 
00124     xnholder_t slink;           /* Thread holder in suspend queue */
00125 
00126     xnpholder_t rlink;          /* Thread holder in ready queue */
00127 
00128     xnpholder_t plink;          /* Thread holder in synchronization queue(s) */
00129 
00130     xnholder_t glink;           /* Thread holder in global queue */
00131 
00132 /* We don't want side-effects on laddr here! */
00133 #define link2thread(laddr,link) \
00134 ((xnthread_t *)(((char *)laddr) - (int)(&((xnthread_t *)0)->link)))
00135 
00136     xnpqueue_t claimq;          /* Owned resources claimed by others (PIP) */
00137 
00138     struct xnsynch *wchan;      /* Resource the thread pends on */
00139 
00140     xntimer_t timer;            /* Delay timer */
00141 
00142     xntimer_t atimer;           /* Asynchronous timer (shadow only) */
00143 
00144     xnsigmask_t signals;        /* Pending signals */
00145 
00146     xnasr_t asr;                /* Asynchronous service routine */
00147 
00148     xnflags_t asrmode;          /* Thread's mode for ASR */
00149 
00150     int asrimask;               /* Thread's interrupt mask for ASR */
00151 
00152     unsigned asrlevel;          /* ASR execution level (ASRs are reentrant) */
00153 
00154     int imask;                  /* Initial interrupt mask */
00155 
00156     int imode;                  /* Initial mode */
00157 
00158     int iprio;                  /* Initial priority */
00159 
00160     xntime_t stime;             /* Start time */
00161 
00162     void (*entry)(void *cookie); /* Thread entry routine */
00163 
00164     void *cookie;               /* Cookie to pass to the entry routine */
00165 
00166     void *extinfo;              /* Extended information -- user-defined */
00167 
00168     void *adcookie;             /* Arch-dependent system cookie. */
00169 
00170     XNARCH_DECL_DISPLAY_CONTEXT();
00171 
00172 } xnthread_t;
00173 
00174 #define XNHOOK_THREAD_START  1
00175 #define XNHOOK_THREAD_SWITCH 2
00176 #define XNHOOK_THREAD_DELETE 3
00177 
00178 typedef struct xnhook {
00179 
00180     xnholder_t link;
00181 
00182 #define link2hook(laddr) \
00183 ((xnhook_t *)(((char *)laddr) - (int)(&((xnhook_t *)0)->link)))
00184 
00185     void (*routine)(xnthread_t *thread);
00186 
00187 } xnhook_t;
00188 
00189 #define xnthread_name(thread)              ((thread)->name)
00190 #define xnthread_sched(thread)             ((thread)->sched)
00191 #define xnthread_start_time(thread)        ((thread)->stime)
00192 #define xnthread_status_flags(thread)      ((thread)->status)
00193 #define xnthread_test_flags(thread,flags)  testbits((thread)->status,flags)
00194 #define xnthread_set_flags(thread,flags)   setbits((thread)->status,flags)
00195 #define xnthread_clear_flags(thread,flags) clrbits((thread)->status,flags)
00196 #define xnthread_initial_priority(thread)  ((thread)->iprio)
00197 #define xnthread_base_priority(thread)     ((thread)->bprio)
00198 #define xnthread_current_priority(thread)  ((thread)->cprio)
00199 #define xnthread_time_slice(thread)        ((thread)->rrperiod)
00200 #define xnthread_time_credit(thread)       ((thread)->rrcredit)
00201 #define xnthread_archtcb(thread)           (&((thread)->tcb))
00202 #define xnthread_asr_level(thread)         ((thread)->asrlevel)
00203 #define xnthread_pending_signals(thread)   ((thread)->signals)
00204 #define xnthread_timeout(thread)           (xntimer_date(&(thread)->timer) - nkpod->jiffies)
00205 #define xnthread_stack_size(thread)        xnarch_stack_size(xnthread_archtcb(thread))
00206 #define xnthread_extended_info(thread)     ((thread)->extinfo)
00207 #define xnthread_magic(thread)             ((thread)->magic)
00208 
00209 #ifdef __cplusplus
00210 extern "C" {
00211 #endif
00212 
00213 int xnthread_init(xnthread_t *thread,
00214                   const char *name,
00215                   int prio,
00216                   xnflags_t flags,
00217                   unsigned stacksize,
00218                   void *adcookie,
00219                   unsigned magic);
00220 
00221 void xnthread_cleanup_tcb(xnthread_t *thread);
00222 
00223 #ifdef __cplusplus
00224 }
00225 #endif
00226 
00227 #endif /* !_xenomai_thread_h */

Generated on Sat Jul 24 19:36:04 2004 for RTAI API by doxygen 1.3.4