synch.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_SYNCH_H
00047 #define _RTAI_NUCLEUS_SYNCH_H
00048 
00049 #include <nucleus/queue.h>
00050 
00051 /* Creation flags */
00052 #define XNSYNCH_FIFO    0x0
00053 #define XNSYNCH_PRIO    0x1
00054 #define XNSYNCH_NOPIP   0x0
00055 #define XNSYNCH_PIP     0x2
00056 
00057 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00058 
00059 #define XNSYNCH_CLAIMED 0x4     /* Claimed by other thread(s) w/ PIP */
00060 
00061 /* Spare flags usable by upper interfaces */
00062 #define XNSYNCH_SPARE0  0x01000000
00063 #define XNSYNCH_SPARE1  0x02000000
00064 #define XNSYNCH_SPARE2  0x04000000
00065 #define XNSYNCH_SPARE3  0x08000000
00066 #define XNSYNCH_SPARE4  0x10000000
00067 #define XNSYNCH_SPARE5  0x20000000
00068 #define XNSYNCH_SPARE6  0x40000000
00069 #define XNSYNCH_SPARE7  0x80000000
00070 
00071 /* Statuses */
00072 #define XNSYNCH_DONE    0       /* Resource available / operation complete */
00073 #define XNSYNCH_WAIT    1       /* Calling thread blocked -- start rescheduling */
00074 #define XNSYNCH_RESCHED 2       /* Force rescheduling */
00075 
00076 struct xnthread;
00077 struct xnsynch;
00078 struct xnmutex;
00079 
00080 typedef struct xnsynch {
00081 
00082     xnpholder_t link;   /* Link in claim queues */
00083 
00084 #define link2synch(laddr) \
00085 ((xnsynch_t *)(((char *)laddr) - (int)(&((xnsynch_t *)0)->link)))
00086 
00087     xnflags_t status;   /* Status word */
00088 
00089     xnpqueue_t pendq;   /* Pending threads */
00090 
00091     struct xnthread *owner; /* Thread which owns the resource */
00092 
00093     XNARCH_DECL_DISPLAY_CONTEXT();
00094 
00095 } xnsynch_t;
00096 
00097 #define xnsynch_test_flags(synch,flags)  testbits((synch)->status,flags)
00098 #define xnsynch_set_flags(synch,flags)   setbits((synch)->status,flags)
00099 #define xnsynch_clear_flags(synch,flags) clrbits((synch)->status,flags)
00100 #define xnsynch_wait_queue(synch)        (&((synch)->pendq))
00101 #define xnsynch_nsleepers(synch)         countpq(&((synch)->pendq))
00102 #define xnsynch_owner(synch)             ((synch)->owner)
00103 
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107 
00108 void xnsynch_init(xnsynch_t *synch,
00109                   xnflags_t flags);
00110 
00111 #define xnsynch_destroy(synch) \
00112 xnsynch_flush(synch,XNRMID)
00113 
00114 static inline void xnsynch_set_owner (xnsynch_t *synch, struct xnthread *thread) {
00115     synch->owner = thread;
00116 }
00117 
00118 void xnsynch_sleep_on(xnsynch_t *synch,
00119                       xnticks_t timeout);
00120 
00121 struct xnthread *xnsynch_wakeup_one_sleeper(xnsynch_t *synch);
00122 
00123 xnpholder_t *xnsynch_wakeup_this_sleeper(xnsynch_t *synch,
00124                                          xnpholder_t *holder);
00125 
00126 int xnsynch_flush(xnsynch_t *synch,
00127                   xnflags_t reason);
00128 
00129 void xnsynch_release_all_ownerships(struct xnthread *thread);
00130 
00131 void xnsynch_renice_sleeper(struct xnthread *thread);
00132 
00133 void xnsynch_forget_sleeper(struct xnthread *thread);
00134 
00135 #ifdef __cplusplus
00136 }
00137 #endif
00138 
00139 #endif /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00140 
00141 #endif /* !_RTAI_NUCLEUS_SYNCH_H_ */

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