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
27namespace fawkes {
28
29class ReadWriteLockData;
30
32{
33public:
34 /** The policy to use for the read/write lock.
35 */
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
70private:
71 ReadWriteLockData *rwlock_data;
72};
73
74} // end namespace fawkes
75
76#endif
Read/write lock to allow multiple readers but only a single writer on the resource at a time.
bool try_lock_for_read()
Tries to aquire a reader lock.
void unlock()
Release the lock.
ReadWriteLockPolicy
The policy to use for the read/write lock.
@ RWLockPolicyPreferWriter
Prefer writers over readers.
@ RWLockPolicyPreferReader
Prefer readers over writers.
void lock_for_read()
Aquire a reader lock.
void lock_for_write()
Aquire a writer lock.
ReadWriteLock(ReadWriteLockPolicy policy=RWLockPolicyPreferWriter)
Constructor.
bool try_lock_for_write()
Tries to aquire a writer lock.
virtual ~ReadWriteLock()
Destructor.
Fawkes library namespace.