Samchon Framework for CPP
1.0.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
UniqueReadLock.hpp
1
#pragma once
2
3
#include <samchon/library/RWMutex.hpp>
4
5
namespace
samchon
6
{
7
namespace
library
8
{
37
class
UniqueReadLock
38
{
39
private
:
43
const
RWMutex
*
rw_mutex
;
44
48
bool
locked
;
49
50
public
:
51
/* -----------------------------------------------------------
52
CONSTRUCTORS
53
----------------------------------------------------------- */
60
UniqueReadLock
(
const
RWMutex
&rw_mutex,
bool
lock
=
true
)
61
{
62
this->rw_mutex = &
rw_mutex
;
63
this->locked =
false
;
64
65
if
(
lock
==
true
)
66
this->
lock
();
67
};
68
79
UniqueReadLock
(
const
UniqueReadLock
&) =
delete
;
80
86
UniqueReadLock
(
UniqueReadLock
&&obj)
87
{
88
//MOVE
89
this->rw_mutex = obj.rw_mutex;
90
this->locked = obj.locked;
91
92
//TRUNCATE
93
obj.rw_mutex =
nullptr
;
94
obj.locked =
false
;
95
};
96
101
~UniqueReadLock
()
102
{
103
if
(locked ==
true
)
104
rw_mutex->
readUnlock
();
105
}
106
107
/* -----------------------------------------------------------
108
LOCKERS
109
----------------------------------------------------------- */
113
void
lock
()
const
114
{
115
if
(locked ==
true
)
116
return
;
117
118
rw_mutex->
readLock
();
119
(
bool
&)locked =
true
;
120
};
121
125
void
unlock
()
const
126
{
127
if
(locked ==
false
)
128
return
;
129
130
rw_mutex->
readUnlock
();
131
(
bool
&)locked =
false
;
132
};
133
137
//auto tryLock() const -> bool;
138
};
139
};
140
};
samchon::library::RWMutex::readUnlock
void readUnlock() const
Unlock of read.
Definition:
RWMutex.hpp:90
samchon::library::RWMutex::readLock
void readLock() const
Lock on read.
Definition:
RWMutex.hpp:67
samchon::library::UniqueReadLock::UniqueReadLock
UniqueReadLock(const RWMutex &rw_mutex, bool lock=true)
Construct from mutex.
Definition:
UniqueReadLock.hpp:60
samchon::library::UniqueReadLock::~UniqueReadLock
~UniqueReadLock()
Default Destructor.
Definition:
UniqueReadLock.hpp:101
samchon::library::UniqueReadLock::lock
void lock() const
Lock on read.
Definition:
UniqueReadLock.hpp:113
samchon::library::UniqueReadLock::unlock
void unlock() const
Unlock of read.
Definition:
UniqueReadLock.hpp:125
samchon::library::UniqueReadLock
Unique lock for reading.
Definition:
UniqueReadLock.hpp:37
samchon::library::UniqueReadLock::UniqueReadLock
UniqueReadLock(UniqueReadLock &&obj)
Move Constructor.
Definition:
UniqueReadLock.hpp:86
samchon::library::UniqueReadLock::locked
bool locked
Whether the mutex was locked by UniqueLock.
Definition:
UniqueReadLock.hpp:48
samchon::library::RWMutex
rw_mutex
Definition:
RWMutex.hpp:29
samchon
Definition:
ByteArray.hpp:6
samchon::library::UniqueReadLock::rw_mutex
const RWMutex * rw_mutex
Managed mutex.
Definition:
UniqueReadLock.hpp:43
cpp
samchon
library
UniqueReadLock.hpp
Generated by
1.8.11