rtai-core/include/xenomai/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 _xenomai_synch_
00047 #define _xenomai_synch_
00048 
00049 #include "xenomai/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 #define XNSYNCH_CLAIMED 0x10    /* Claimed by other thread(s) w/ PIP */
00058 #define XNSYNCH_KMUTEX  0x20    /* A kernel mutex base */
00059 
00060 /* Spare flags usable by upper interfaces */
00061 #define XNSYNCH_SPARE0  0x01000000
00062 #define XNSYNCH_SPARE1  0x02000000
00063 #define XNSYNCH_SPARE2  0x04000000
00064 #define XNSYNCH_SPARE3  0x08000000
00065 #define XNSYNCH_SPARE4  0x10000000
00066 #define XNSYNCH_SPARE5  0x20000000
00067 #define XNSYNCH_SPARE6  0x40000000
00068 #define XNSYNCH_SPARE7  0x80000000
00069 
00070 /* Statuses */
00071 #define XNSYNCH_DONE    0       /* Resource available / operation complete */
00072 #define XNSYNCH_WAIT    1       /* Calling thread blocked -- start rescheduling */
00073 #define XNSYNCH_RESCHED 2       /* Force rescheduling */
00074 
00075 struct xnthread;
00076 struct xnsynch;
00077 struct xnmutex;
00078 
00079 typedef struct xnsynch {
00080 
00081     xnpholder_t link;   /* Link in claim queues */
00082 
00083 #define link2synch(laddr) \
00084 ((xnsynch_t *)(((char *)laddr) - (int)(&((xnsynch_t *)0)->link)))
00085 
00086     xnflags_t status;   /* Status word */
00087 
00088     xnpqueue_t pendq;   /* Pending threads */
00089 
00090     struct xnthread *owner; /* Thread which owns the resource */
00091 
00092     XNARCH_DECL_DISPLAY_CONTEXT();
00093 
00094 } xnsynch_t;
00095 
00096 #define xnsynch_test_flags(synch,flags)  testbits((synch)->status,flags)
00097 #define xnsynch_set_flags(synch,flags)   setbits((synch)->status,flags)
00098 #define xnsynch_clear_flags(synch,flags) clrbits((synch)->status,flags)
00099 #define xnsynch_wait_queue(synch)        (&((synch)->pendq))
00100 #define xnsynch_nsleepers(synch)         countpq(&((synch)->pendq))
00101 #define xnsynch_owner(synch)             ((synch)->owner)
00102 
00103 #ifdef __cplusplus
00104 extern "C" {
00105 #endif
00106 
00107 void xnsynch_init(xnsynch_t *synch,
00108                   xnflags_t flags);
00109 
00110 #define xnsynch_destroy(synch) \
00111 xnsynch_flush(synch,XNRMID)
00112 
00113 static inline void xnsynch_set_owner (xnsynch_t *synch, struct xnthread *thread) {
00114     synch->owner = thread;
00115 }
00116 
00117 void xnsynch_sleep_on(xnsynch_t *synch,
00118                       xnticks_t timeout,
00119                       struct xnmutex *imutex);
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 /* !_xenomai_synch_ */

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