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 
30 class ReadWriteLockData;
31 
33 {
34  public:
35 
36  /** The policy to use for the read/write lock.
37  */
39  RWLockPolicyPreferWriter, /**< Prefer writers over readers. A writer
40  * is granted prefered access to the lock.
41  * This means that the writer can aquire
42  * the lock as soon as all readers unlocked
43  * it not matter if there are readers queued
44  * and waiting for the lock. This is the
45  * default behaviour. Not with multiple
46  * writers you can run into the problem of
47  * reader starvation.
48  */
49  RWLockPolicyPreferReader /**< Prefer readers over writers. This is
50  * similar to the writer preference. Readers
51  * will be allowed to aquire the lock no
52  * matter if there is a writer enqueued for
53  * the lock. Not that with many readers
54  * (depending on the time they aquire the
55  * lock this can already start with two
56  * or three readers) you can run into the
57  * problem of writer starvation: the writer
58  * can never aquire the lock.
59  */
60  };
61 
63 
64  virtual ~ReadWriteLock();
65 
66  void lock_for_read();
67  void lock_for_write();
68  bool try_lock_for_read();
69  bool try_lock_for_write();
70  void unlock();
71 
72  private:
73  ReadWriteLockData *rwlock_data;
74 };
75 
76 
77 } // end namespace fawkes
78 
79 #endif
void lock_for_read()
Aquire a reader lock.
bool try_lock_for_write()
Tries to aquire a writer lock.
bool try_lock_for_read()
Tries to aquire a reader lock.
Fawkes library namespace.
void lock_for_write()
Aquire a writer lock.
ReadWriteLock(ReadWriteLockPolicy policy=RWLockPolicyPreferWriter)
Constructor.
Read/write lock to allow multiple readers but only a single writer on the resource at a time...
virtual ~ReadWriteLock()
Destructor.
void unlock()
Release the lock.
ReadWriteLockPolicy
The policy to use for the read/write lock.