Samchon Framework for CPP
1.0.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
UniqueWriteLock.hpp
1
#pragma once
2
3
#include <samchon/library/RWMutex.hpp>
4
5
namespace
samchon
6
{
7
namespace
library
8
{
39
class
UniqueWriteLock
40
{
41
private
:
45
RWMutex
*
rw_mutex
;
46
50
bool
locked
;
51
52
public
:
53
/* -----------------------------------------------------------
54
CONSTRUCTORS
55
----------------------------------------------------------- */
62
UniqueWriteLock
(
RWMutex
&rw_mutex,
bool
lock
=
true
)
63
{
64
this->rw_mutex = &
rw_mutex
;
65
this->locked =
false
;
66
67
if
(
lock
==
true
)
68
this->
lock
();
69
};
70
81
UniqueWriteLock
(
const
UniqueWriteLock
&) =
delete
;
82
88
UniqueWriteLock
(
UniqueWriteLock
&&obj)
89
{
90
//MOVE
91
this->rw_mutex = obj.rw_mutex;
92
this->locked = obj.locked;
93
94
//TRUNCATE
95
obj.rw_mutex =
nullptr
;
96
obj.locked =
false
;
97
};
98
105
~UniqueWriteLock
()
106
{
107
if
(locked ==
true
)
108
rw_mutex->
writeUnlock
();
109
};
110
111
/* -----------------------------------------------------------
112
LOCKERS
113
----------------------------------------------------------- */
117
void
lock
()
118
{
119
if
(locked ==
true
)
120
return
;
121
122
rw_mutex->
writeLock
();
123
locked =
true
;
124
};
125
129
void
unlock
()
130
{
131
if
(locked ==
false
)
132
return
;
133
134
rw_mutex->
writeUnlock
();
135
locked =
false
;
136
};
137
141
//auto tryLock() -> bool;
142
};
143
};
144
};
samchon::library::UniqueWriteLock::UniqueWriteLock
UniqueWriteLock(UniqueWriteLock &&obj)
Move Constructor.
Definition:
UniqueWriteLock.hpp:88
samchon::library::RWMutex::writeLock
void writeLock()
Lock on writing.
Definition:
RWMutex.hpp:117
samchon::library::UniqueWriteLock::UniqueWriteLock
UniqueWriteLock(RWMutex &rw_mutex, bool lock=true)
Construct from mutex.
Definition:
UniqueWriteLock.hpp:62
samchon::library::UniqueWriteLock::~UniqueWriteLock
~UniqueWriteLock()
Destructor.
Definition:
UniqueWriteLock.hpp:105
samchon::library::UniqueWriteLock
Unique lock for writing.
Definition:
UniqueWriteLock.hpp:39
samchon::library::UniqueWriteLock::lock
void lock()
Lock on writing.
Definition:
UniqueWriteLock.hpp:117
samchon::library::UniqueWriteLock::unlock
void unlock()
Unlock on writing.
Definition:
UniqueWriteLock.hpp:129
samchon::library::UniqueWriteLock::locked
bool locked
Whether the mutex was locked by UniqueLock.
Definition:
UniqueWriteLock.hpp:50
samchon::library::UniqueWriteLock::rw_mutex
RWMutex * rw_mutex
Managed mutex.
Definition:
UniqueWriteLock.hpp:45
samchon::library::RWMutex
rw_mutex
Definition:
RWMutex.hpp:29
samchon::library::RWMutex::writeUnlock
void writeUnlock()
Unlock on writing.
Definition:
RWMutex.hpp:130
samchon
Definition:
ByteArray.hpp:6
cpp
samchon
library
UniqueWriteLock.hpp
Generated by
1.8.11