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

LOW_thread_rwlock_POSIX.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_thread_rwlock_POSIX.h  -  description
00003                              -------------------
00004     begin                : Sun Oct 5 2003
00005     copyright            : (C) 2003 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef LOW_THREAD_RWLOCK_POSIX_H
00019 #define LOW_THREAD_RWLOCK_POSIX_H
00020 
00021 
00022 #include "LOW_thread_rwlock.h"
00023 
00024 
00025 #include <pthread.h>
00026 
00027 
00028 
00029 /** Platform specific LOW_thread_rwlock for POSIX platforms.
00030 
00031     This class is thread-safe.
00032 
00033     @see LOW_thread_rwlock
00034     @see IEEE Standard 1003.1-2003 (http://www.opengroup.org/onlinepubs/007904975/toc.htm)
00035   
00036     @author Harald Roelle
00037     @author Parts of the documentation taken from Linux man pages by Xavier Leroy.
00038     @author Parts of the documentation taken from IEEE Standard 1003.1-2003.
00039  */
00040 class LOW_thread_rwlock_POSIX : public LOW_thread_rwlock {
00041 
00042 //=======================================================================================
00043 public:
00044 
00045   //=====================================================================================
00046   //
00047   // constructors
00048   //
00049 
00050   /** Destructor.
00051       @throw thread_rwlock_busy    The lock is still locked.
00052       @throw thread_rwlock_error   Any other error.
00053    */
00054   virtual ~LOW_thread_rwlock_POSIX();
00055 
00056 
00057   //=====================================================================================
00058   //
00059   // methods
00060   //
00061 
00062   /** Obtain a read lock on the rwlock (blocking).
00063 
00064       The method applies a read lock to the read-write lock.
00065       The calling thread acquires the read lock if a writer does not hold the lock and
00066       there are no writers blocked on the lock.
00067 
00068       A thread may hold multiple concurrent read locks on rwlock (that is, successfully
00069       call the lockRead() method n times). If so, the application shall ensure that the
00070       thread performs matching unlocks (that is, it calls unlock() method n times).
00071 
00072       @throw thread_rwlock_locked  Calling thread already owns rwlock for writing.
00073       @throw thread_rwlock_error   Any other error.
00074    */
00075   virtual void lockRead();
00076 
00077 
00078   /** Obtain a read lock on the rwlock (non-blocking).
00079 
00080       The method applies a read lock as in the lockRead() method, with the exception
00081       that the function throws an exception if the equivalent lockRead() call would
00082       have blocked the calling thread. The method never blocks; it always either
00083       acquires the lock or throws a thread_rwlock_busy exception.
00084 
00085       @throw thread_rwlock_busy    The rwlock is already locked for writing by another thread.
00086       @throw thread_rwlock_locked  Calling thread already owns rwlock for writing.
00087       @throw thread_rwlock_error   Any other error.
00088    */
00089   virtual void tryLockRead();
00090 
00091 
00092   /** Obtain a write lock on the rwlock (blocking).
00093 
00094       The method applies a write lock to the read-write lock.
00095       The calling thread acquires the write lock if no other thread (reader or writer)
00096       holds the read-write lock rwlock. Otherwise, the thread will block until it can
00097       acquire the lock. The calling thread may deadlock if at the time the call is made
00098       it holds the read-write lock (whether a read or write lock).
00099 
00100       @throw thread_rwlock_locked  Calling thread already owns the read-write lock for writing or reading.
00101       @throw thread_rwlock_error   Any other error.
00102    */
00103   virtual void lockWrite();
00104 
00105 
00106   /** Obtain a write lock on the rwlock (non-blocking).
00107 
00108       The method applies a write lock like the lockWrite() method, with the exception
00109       that the function throws an exception if any thread currently holds the
00110       rwlock (for reading or writing).
00111 
00112       @throw thread_rwlock_busy    The rwlock is already locked for reading or writing.
00113       @throw thread_rwlock_locked  Calling thread already owns the read-write lock for writing or reading.
00114       @throw thread_rwlock_error   Any other error.
00115    */
00116   virtual void tryLockWrite();
00117 
00118 
00119   /** Release a lock on the rwlock.
00120 
00121       The method releasees a lock held on the read-write lock. Results are undefined if the read-write
00122       lock rwlock is not held by the calling thread.
00123 
00124       If this method is called to release a read lock from the read-write lock object and
00125       there are other read locks currently held on this read-write lock object, the read-write
00126       lock object remains in the read locked state. If this method releases the last read lock
00127       for this read-write lock object, the read-write lock object is put in the unlocked
00128       state with no owners.
00129 
00130       If this method is called to release a write lock for this read-write lock object,
00131       the read-write lock object is put in the unlocked state.
00132 
00133       @throw thread_rwlock_busy    calling thread does not hold a lock.
00134       @throw thread_rwlock_error   Any other error.
00135    */
00136   virtual void unlock();
00137 
00138 
00139   
00140 //=======================================================================================
00141 protected:
00142 
00143   //=====================================================================================
00144   //
00145   // friend classes
00146   //
00147 
00148   friend class LOW_thread_Factory; /**< To allow construction. */
00149 
00150 
00151   //=====================================================================================
00152   //
00153   // constructors
00154   //
00155 
00156   /** Constructor.
00157       Not publicly constructable. Use LOW_thread_Factory.
00158       @throw thread_rwlock_error   Any error.
00159    */
00160   LOW_thread_rwlock_POSIX();
00161 
00162 
00163   
00164 //=======================================================================================
00165 private:
00166 
00167   //=====================================================================================
00168   //
00169   // attributes
00170   //
00171 
00172   pthread_rwlock_t      theRwlock;   /**< The rwlock itself. */
00173 
00174 };
00175 
00176 #endif

Generated on Tue Feb 3 11:30:26 2004 for OneWireLibrary++ by doxygen 1.3.2