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

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