Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * read_write_lock.h - Read Write Lock 00004 * 00005 * Generated: Thu Sep 15 00:07:41 2006 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __CORE_THREADING_READ_WRITE_LOCK_H_ 00025 #define __CORE_THREADING_READ_WRITE_LOCK_H_ 00026 00027 namespace fawkes { 00028 00029 00030 class ReadWriteLockData; 00031 00032 class ReadWriteLock 00033 { 00034 public: 00035 00036 /** The policy to use for the read/write lock. 00037 */ 00038 enum ReadWriteLockPolicy { 00039 RWLockPolicyPreferWriter, /**< Prefer writers over readers. A writer 00040 * is granted prefered access to the lock. 00041 * This means that the writer can aquire 00042 * the lock as soon as all readers unlocked 00043 * it not matter if there are readers queued 00044 * and waiting for the lock. This is the 00045 * default behaviour. Not with multiple 00046 * writers you can run into the problem of 00047 * reader starvation. 00048 */ 00049 RWLockPolicyPreferReader /**< Prefer readers over writers. This is 00050 * similar to the writer preference. Readers 00051 * will be allowed to aquire the lock no 00052 * matter if there is a writer enqueued for 00053 * the lock. Not that with many readers 00054 * (depending on the time they aquire the 00055 * lock this can already start with two 00056 * or three readers) you can run into the 00057 * problem of writer starvation: the writer 00058 * can never aquire the lock. 00059 */ 00060 }; 00061 00062 ReadWriteLock(ReadWriteLockPolicy policy = RWLockPolicyPreferWriter); 00063 00064 virtual ~ReadWriteLock(); 00065 00066 void lock_for_read(); 00067 void lock_for_write(); 00068 bool try_lock_for_read(); 00069 bool try_lock_for_write(); 00070 void unlock(); 00071 00072 private: 00073 ReadWriteLockData *rwlock_data; 00074 }; 00075 00076 00077 } // end namespace fawkes 00078 00079 #endif