Samchon Framework for CPP  1.0.0
UniqueAcquire.cpp
1 #include <samchon/library/UniqueAcquire.hpp>
2 #include <samchon/library/Semaphore.hpp>
3 
4 using namespace samchon::library;
5 
6 /* -----------------------------------------------------------
7  CONSTRUCTORS
8 ----------------------------------------------------------- */
9 UniqueAcquire::UniqueAcquire(Semaphore &semaphore, bool doLock)
10 {
11  if(doLock == true)
12  semaphore.acquire();
13 
14  this->semaphore = &semaphore;
15  this->isLocked = doLock;
16 }
18 {
19  //MOVE
20  this->semaphore = obj.semaphore;
21  this->isLocked = obj.isLocked;
22 
23  //TRUNCATE
24  obj.semaphore = nullptr;
25  obj.isLocked = nullptr;
26 }
28 {
29  if(isLocked == true)
30  semaphore->release();
31 }
32 
33 /* -----------------------------------------------------------
34  LOCKERS
35 ----------------------------------------------------------- */
37 {
38  if(isLocked == true)
39  return;
40 
41  semaphore->acquire();
42  isLocked = true;
43 }
45 {
46  if(isLocked == false)
47  return;
48 
49  semaphore->release();
50  isLocked = false;
51 }
bool isLocked
Whether the semaphore was acquired by the UniqueLock.
void acquire()
Acquire admission.
Package of libraries.
Definition: library.hpp:84
UniqueAcquire(Semaphore &, bool=true)
Construct from semaphore.
void release()
Release an admission.
void release()
Release an admission.
Definition: Semaphore.cpp:75
void acquire()
Acquire admission.
Definition: Semaphore.cpp:50
Unique acquire from a Semaphore.
~UniqueAcquire()
Default Destructor.
Semaphore * semaphore
Managed semaphore.