Fawkes API  Fawkes Development Version
read_write_lock.h
1 
2 /***************************************************************************
3  * read_write_lock.h - Read Write Lock
4  *
5  * Generated: Thu Sep 15 00:07:41 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _CORE_THREADING_READ_WRITE_LOCK_H_
25 #define _CORE_THREADING_READ_WRITE_LOCK_H_
26 
27 namespace fawkes {
28 
29 class ReadWriteLockData;
30 
31 class ReadWriteLock
32 {
33 public:
34  /** The policy to use for the read/write lock.
35  */
36  enum ReadWriteLockPolicy {
37  RWLockPolicyPreferWriter, /**< Prefer writers over readers. A writer
38  * is granted prefered access to the lock.
39  * This means that the writer can aquire
40  * the lock as soon as all readers unlocked
41  * it not matter if there are readers queued
42  * and waiting for the lock. This is the
43  * default behaviour. Not with multiple
44  * writers you can run into the problem of
45  * reader starvation.
46  */
47  RWLockPolicyPreferReader /**< Prefer readers over writers. This is
48  * similar to the writer preference. Readers
49  * will be allowed to aquire the lock no
50  * matter if there is a writer enqueued for
51  * the lock. Not that with many readers
52  * (depending on the time they aquire the
53  * lock this can already start with two
54  * or three readers) you can run into the
55  * problem of writer starvation: the writer
56  * can never aquire the lock.
57  */
58  };
59 
61 
62  virtual ~ReadWriteLock();
63 
64  void lock_for_read();
65  void lock_for_write();
66  bool try_lock_for_read();
67  bool try_lock_for_write();
68  void unlock();
69 
70 private:
71  ReadWriteLockData *rwlock_data;
72 };
73 
74 } // end namespace fawkes
75 
76 #endif
fawkes::ReadWriteLock::try_lock_for_read
bool try_lock_for_read()
Tries to aquire a reader lock.
Definition: read_write_lock.cpp:120
fawkes::ReadWriteLock::lock_for_read
void lock_for_read()
Aquire a reader lock.
Definition: read_write_lock.cpp:97
fawkes::ReadWriteLock::~ReadWriteLock
virtual ~ReadWriteLock()
Destructor.
Definition: read_write_lock.cpp:85
fawkes::ReadWriteLock::RWLockPolicyPreferReader
Prefer readers over writers.
Definition: read_write_lock.h:51
fawkes
fawkes::ReadWriteLock::lock_for_write
void lock_for_write()
Aquire a writer lock.
Definition: read_write_lock.cpp:108
fawkes::ReadWriteLock::unlock
void unlock()
Release the lock.
Definition: read_write_lock.cpp:141
fawkes::ReadWriteLock::ReadWriteLockPolicy
ReadWriteLockPolicy
The policy to use for the read/write lock.
Definition: read_write_lock.h:40
fawkes::ReadWriteLock::ReadWriteLock
ReadWriteLock(ReadWriteLockPolicy policy=RWLockPolicyPreferWriter)
Constructor.
Definition: read_write_lock.cpp:61
fawkes::ReadWriteLock::RWLockPolicyPreferWriter
Prefer writers over readers.
Definition: read_write_lock.h:41
fawkes::ReadWriteLock::try_lock_for_write
bool try_lock_for_write()
Tries to aquire a writer lock.
Definition: read_write_lock.cpp:132