Mixe for Privacy and Anonymity in the Internet
CAReadWriteLock.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2020, The JAP-Team
3
All rights reserved.
4
Redistribution and use in source and binary forms, with or without modification,
5
are permitted provided that the following conditions are met:
6
7
- Redistributions of source code must retain the above copyright notice,
8
this list of conditions and the following disclaimer.
9
10
- Redistributions in binary form must reproduce the above copyright notice,
11
this list of conditions and the following disclaimer in the documentation and/or
12
other materials provided with the distribution.
13
14
- Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15
may be used to endorse or promote products derived from this software without specific
16
prior written permission.
17
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27
*/
28
#ifndef __CAREADWRITELOCK__
29
#define __CAREADWRITELOCK__
30
#ifndef HAVE_PTHREAD_MUTEXES
31
#include "
CAMutex.hpp
"
32
#endif
33
34
class
CAReadWriteLock
35
{
36
public
:
37
CAReadWriteLock
();
38
~CAReadWriteLock
();
39
40
SINT32
lockRead
()
41
{
42
#ifdef HAVE_PTHREAD_MUTEXES
43
if
(pthread_rwlock_rdlock(
m_pMutex
)==0)
44
return
E_SUCCESS
;
45
return
E_UNKNOWN
;
46
#else
47
return
m_pMutex
->down();
48
#endif
49
}
50
51
SINT32
lockWrite
()
52
{
53
#ifdef HAVE_PTHREAD_MUTEXES
54
if
(pthread_rwlock_wrlock(
m_pMutex
)==0)
55
return
E_SUCCESS
;
56
return
E_UNKNOWN
;
57
#else
58
return
m_pMutex
->down();
59
#endif
60
}
61
62
SINT32
unlock
()
63
{
64
#ifdef HAVE_PTHREAD_MUTEXES
65
if
(pthread_rwlock_unlock(
m_pMutex
) == 0)
66
return
E_SUCCESS
;
67
return
E_UNKNOWN
;
68
#else
69
return
m_pMutex
->up();
70
#endif
71
}
72
73
74
75
private
:
76
#ifdef HAVE_PTHREAD_MUTEXES
77
pthread_rwlock_t*
m_pMutex
;
78
#else
79
CAMutex
*
m_pMutex
;
80
#endif
81
82
};
83
#endif
CAMutex.hpp
SINT32
signed int SINT32
Definition:
basetypedefs.h:132
CAMutex
Definition:
CAMutex.hpp:36
CAReadWriteLock
Definition:
CAReadWriteLock.hpp:35
CAReadWriteLock::unlock
SINT32 unlock()
Definition:
CAReadWriteLock.hpp:62
CAReadWriteLock::CAReadWriteLock
CAReadWriteLock()
Definition:
CAReadWriteLock.cpp:33
CAReadWriteLock::~CAReadWriteLock
~CAReadWriteLock()
Definition:
CAReadWriteLock.cpp:43
CAReadWriteLock::lockRead
SINT32 lockRead()
Definition:
CAReadWriteLock.hpp:40
CAReadWriteLock::lockWrite
SINT32 lockWrite()
Definition:
CAReadWriteLock.hpp:51
CAReadWriteLock::m_pMutex
CAMutex * m_pMutex
Definition:
CAReadWriteLock.hpp:79
E_SUCCESS
const SINT32 E_SUCCESS
Definition:
errorcodes.hpp:2
E_UNKNOWN
#define E_UNKNOWN
Definition:
errorcodes.hpp:3
Generated on Sat Jul 22 2023 00:20:11 for Mixe for Privacy and Anonymity in the Internet by
1.9.1