Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/threads/rwlock.h

Go to the documentation of this file.
00001 /*
00002  * lib/threads/rwlock.h
00003  * 
00004  * Implementing a thread-save read/write lock. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _ThreadLibrary_ReadWriteLock_H_
00018 #define _ThreadLibrary_ReadWriteLock_H_ 1
00019 
00026 #include <lib/sconfig.h>    /* MUST be first */
00027 
00028 #include <glib/gthread.h>
00029 
00046 class /*_packed_*/ ReadWriteLock
00047 {
00048     private:
00049         GStaticRWLock l;  
00050         
00051     public:
00053         inline ReadWriteLock()
00054             {  g_static_rw_lock_init(&l);  }
00055         
00057         inline ~ReadWriteLock()
00058             {  g_static_rw_lock_free(&l);  }
00059         
00072         inline void ReadLock()
00073             {  g_static_rw_lock_reader_lock(&l);  }
00074         
00085         inline bool ReadTest()
00086             {  return(g_static_rw_lock_reader_trylock(&l));  }
00087         
00092         inline void ReadUnlock()
00093             {  g_static_rw_lock_reader_unlock(&l);  }
00094         
00108         inline void WriteLock()
00109             {  g_static_rw_lock_writer_lock(&l);  }
00110         
00121         inline bool WriteTest()
00122             {  return(g_static_rw_lock_writer_trylock(&l));  }
00123         
00128         inline void WriteUnlock()
00129             {  g_static_rw_lock_writer_unlock(&l);  }
00130         
00131 };
00132 
00133 #endif  /* _ThreadLibrary_ReadWriteLock_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5