blob: 47b78a50edc9f1f00dc4a781ef72dbd76642dee1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* @author Peter Boros
* @date 2004/09/07
* @version $Id$
* @file rwlock.h
* @brief Read-write lock.
*
*/
#pragma once
namespace fsa {
// {{{ class RWLock
/**
* @class RWLock
* @brief Read-write lock.
*
* Simple read-write lock class based on POSIX pthread_rwlock_t.
*/
class RWLock
{
protected:
struct Impl;
Impl *_impl;
public:
/**
* @brief Constructor.
*/
RWLock(void);
/**
* @brief Destructor.
*/
~RWLock(void);
/**
* @brief Try to get a read (shared) lock.
*
* Try to get a read (shared) lock. This method is non-blocking, and
* returns true if locking was succesful.
*
* @return True if locking was successful.
*/
bool tryRdLock (void);
/**
* @brief Try to get a write (exclusive) lock.
*
* Try to get a write (exclusive) lock. This method is non-blocking, and
* returns true if locking was succesful.
*
* @return True if locking was successful.
*/
bool tryWrLock (void);
/**
* @brief Get a read (shared) lock.
*
* Get a read (shared) lock. This method blocks until a shared
* lock is available (that is no other thread holds an exclusive
* lock on the object.)
*
* @return True if locking was successful.
*/
bool rdLock (void);
/**
* @brief Get a write (exclusive) lock.
*
* Get a write (exclusive) lock. This method blocks until an
* exclusive lock is available (that is no other thread holds a
* shared or an exclusive lock on the object.)
*
* @return True if locking was successful.
*/
bool wrLock (void);
/**
* @brief Release a (shared or exclusive) lock.
*
* @return True if unlocking was successful.
*/
bool unlock (void);
};
// }}}
} // namespace fsa
|