/home/hillier_g/checkout/most4linux/most-kernel/rtseqlock.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright(c) Siemens AG, Muenchen, Germany, 2005, 2006, 2007
00003  *                           Bernhard Walle <bernhard.walle@gmx.de>
00004  *                           Gernot Hillier <gernot.hillier@siemens.com>
00005  *
00006  * ----------------------------------------------------------------------------
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as 
00009  * published by the Free Software Foundation;
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * ----------------------------------------------------------------------------
00020  */
00021 #ifndef RTSEQLOCK_H
00022 #define RTSEQLOCK_H
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include "config/config.h"
00026 #endif
00027 #include <asm/system.h>
00028 #include <rtdm/rtdm_driver.h>
00029 
00070 typedef struct {
00071     unsigned int        sequence;       
00072     rtdm_lock_t         lock;           
00073 } rt_seqlock_t;
00074 
00078 #define RT_SEQLOCK_UNLOCKED { 0, RTDM_LOCK_UNLOCKED }
00079 
00083 #define rt_seqlock_init(x)                                          \
00084     do {                                                            \
00085         *(x) = (rt_seqlock_t)RT_SEQLOCK_UNLOCKED;                   \
00086     } while (0)
00087 
00095 static inline void rt_write_seqlock(seqlock_t *sl)
00096 {
00097     rtdm_lock_get(&sl->lock);
00098     ++sl->sequence;
00099     smp_wmb();
00100 }
00101 
00107 static inline void rt_write_sequnlock(seqlock_t *sl) 
00108 {
00109     smp_wmb();
00110     sl->sequence++;
00111     rtdm_lock_put(&sl->lock);
00112 }
00113 
00121 static inline unsigned int rt_read_seqbegin(const seqlock_t *sl)
00122 {
00123     unsigned ret = sl->sequence;
00124     smp_rmb();
00125     return ret;
00126 }
00127 
00142 static inline int rt_read_seqretry(const seqlock_t *sl, unsigned int iv)
00143 {
00144     smp_rmb();
00145     return (iv & 1) | (sl->sequence ^ iv);
00146 }
00147 
00154 #define rt_write_seqlock_irqsave(sl, flags)                         \
00155     do {                                                            \
00156         rtdm_lock_get_irqsave(&sl->lock, flags);                    \
00157         ++sl->sequence;                                             \
00158         smp_wmb();                                                  \
00159     } while (0)
00160 
00161 
00168 #define rt_write_sequnlock_irqrestore(sl, flags)                    \
00169     do {                                                            \
00170         smp_wmb();                                                  \
00171         sl->sequence++;                                             \
00172         rtdm_lock_put_irqrestore(&sl->lock, flags);                 \
00173     } while (0)
00174 
00175 
00176 #endif /* RTSEQLOCK_H */
00177 
00178 /* vim: set ts=4 sw=4 et: */

Generated on Fri Mar 9 14:48:58 2007 for MOST Linux Drivers (Linux and RTAI) by  doxygen 1.5.0