Fawkes API
Fawkes Development Version
scoped_rwlock.h
1
2
/***************************************************************************
3
* scoped_rwlock.h - Scoped read/write lock
4
*
5
* Created: Mon Jan 10 11:42:56 2011
6
* Copyright 2006-2010 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_SCOPED_RWLOCK_H_
25
#define _CORE_THREADING_SCOPED_RWLOCK_H_
26
27
#include <core/utils/refptr.h>
28
29
namespace
fawkes
{
30
31
class
ReadWriteLock;
32
33
class
ScopedRWLock
34
{
35
public
:
36
/** What to lock for. */
37
typedef
enum
{
38
LOCK_WRITE
,
///< Lock for writing
39
LOCK_READ
///< Lock for reading
40
}
LockType
;
41
42
ScopedRWLock
(
RefPtr<ReadWriteLock>
rwlock,
43
LockType
lock_type =
LOCK_WRITE
,
44
bool
initially_lock =
true
);
45
ScopedRWLock
(
ReadWriteLock
*rwlock,
LockType
lock_type =
LOCK_WRITE
,
bool
initially_lock =
true
);
46
~ScopedRWLock
();
47
48
void
relock
();
49
void
unlock
();
50
51
private
:
52
LockType
lock_type_;
53
bool
locked_;
54
RefPtr<ReadWriteLock>
refrwlock_;
55
ReadWriteLock
* rawrwlock_;
56
};
57
58
}
// end namespace fawkes
59
60
#endif
fawkes::RefPtr
RefPtr<> is a reference-counting shared smartpointer.
Definition:
refptr.h:50
fawkes::ScopedRWLock::LOCK_READ
@ LOCK_READ
Lock for reading.
Definition:
scoped_rwlock.h:39
fawkes::ScopedRWLock
Scoped read/write lock.
Definition:
scoped_rwlock.h:34
fawkes::ScopedRWLock::relock
void relock()
Lock this rwlock, again.
Definition:
scoped_rwlock.cpp:146
fawkes::ReadWriteLock
Read/write lock to allow multiple readers but only a single writer on the resource at a time.
Definition:
read_write_lock.h:32
fawkes
Fawkes library namespace.
fawkes::ScopedRWLock::LockType
LockType
What to lock for.
Definition:
scoped_rwlock.h:37
fawkes::ScopedRWLock::unlock
void unlock()
Unlock the rwlock.
Definition:
scoped_rwlock.cpp:166
fawkes::ScopedRWLock::ScopedRWLock
ScopedRWLock(RefPtr< ReadWriteLock > rwlock, LockType lock_type=LOCK_WRITE, bool initially_lock=true)
Constructor.
Definition:
scoped_rwlock.cpp:91
fawkes::ScopedRWLock::LOCK_WRITE
@ LOCK_WRITE
Lock for writing.
Definition:
scoped_rwlock.h:38
fawkes::ScopedRWLock::~ScopedRWLock
~ScopedRWLock()
Destructor.
Definition:
scoped_rwlock.cpp:131
src
libs
core
threading
scoped_rwlock.h
Generated by
1.8.20