1 #include <samchon/library/SharedReadLock.hpp> 4 #include <samchon/library/RWMutex.hpp> 12 SharedReadLock::SharedReadLock(
const RWMutex &semaphore,
bool doLock)
17 this->semaphore = &semaphore;
19 this->reference =
new atomic<size_t>(1);
20 this->isLocked =
new atomic<bool>(doLock);
33 this->semaphore = obj.semaphore;
34 this->reference = obj.reference;
35 this->isLocked = obj.isLocked;
38 obj.semaphore =
nullptr;
39 obj.reference =
nullptr;
40 obj.isLocked =
nullptr;
43 SharedReadLock::~SharedReadLock()
45 if(reference ==
nullptr || reference->operator--() > 0)
48 if(isLocked->load() ==
true)
49 semaphore->readUnlock();
58 void SharedReadLock::lock()
const 60 if(isLocked->load() ==
true)
63 semaphore->readLock();
64 isLocked->store(
true);
66 void SharedReadLock::unlock()
const 68 if(isLocked->load() ==
false)
71 semaphore->readUnlock();
72 isLocked->store(
false);
Shared lock from a RWMutex.
const RWMutex * semaphore
Managed RWMutex.
std::atomic< size_t > * reference
Referencing count sharing same RWMutex.
std::atomic< bool > * isLocked
Whether the mutex was locked by SharedReadLock.
void readLock() const
Lock on read.