mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
add the internal counter mutex lock. Move the code of the rw mutec to the rsthreads.cc file
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2697 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5974ac004e
commit
ffdd38ddd5
@ -144,3 +144,49 @@ void RsQueueThread::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsReadWriteMutex::RsReadWriteMutex():readLocks(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::readLock() {
|
||||||
|
internalCounterMtx.lock();//lock internal read counter
|
||||||
|
if (readLocks == 0) {
|
||||||
|
lock(); //lock normal mutex
|
||||||
|
}
|
||||||
|
readLocks++;
|
||||||
|
internalCounterMtx.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::readUnlock() {
|
||||||
|
internalCounterMtx.lock();//lock internal read counter
|
||||||
|
if (readLocks == 1) {
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
if (readLocks != 0) {
|
||||||
|
readLocks--;
|
||||||
|
}
|
||||||
|
internalCounterMtx.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::writeLock() {
|
||||||
|
lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::writeUnlock() {
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::rwlock(uint32_t type) {
|
||||||
|
if (type & READ_LOCK) {
|
||||||
|
readLock();
|
||||||
|
} else {
|
||||||
|
writeLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsReadWriteMutex::rwunlock(uint32_t type) {
|
||||||
|
if (type & READ_LOCK) {
|
||||||
|
readUnlock();
|
||||||
|
} else {
|
||||||
|
writeUnlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -101,15 +101,15 @@ class RsStackMutex
|
|||||||
class RsReadWriteMutex: public RsMutex
|
class RsReadWriteMutex: public RsMutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsReadWriteMutex(): readLocks(0) { }
|
RsReadWriteMutex();
|
||||||
|
|
||||||
void readLock() { if (readLocks == 0) {lock();} ; readLocks++;}
|
void readLock();
|
||||||
void readUnlock() { if (readLocks == 1) {unlock();} if (readLocks != 0) {readLocks--;} }
|
void readUnlock();
|
||||||
void writeLock() {lock();}
|
void writeLock();
|
||||||
void writeUnlock() {unlock();}
|
void writeUnlock();
|
||||||
|
|
||||||
void rwlock(uint32_t type) { if (type & READ_LOCK) {readLock();} else {writeLock();} }
|
void rwlock(uint32_t type);
|
||||||
void rwunlock(uint32_t type) { if (type & READ_LOCK) {readUnlock();} else {writeUnlock();} }
|
void rwunlock(uint32_t type);
|
||||||
|
|
||||||
const static uint32_t READ_LOCK = 0x0001;
|
const static uint32_t READ_LOCK = 0x0001;
|
||||||
const static uint32_t WRITE_LOCK = 0x0002;
|
const static uint32_t WRITE_LOCK = 0x0002;
|
||||||
@ -117,6 +117,7 @@ class RsReadWriteMutex: public RsMutex
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int readLocks;
|
int readLocks;
|
||||||
|
RsMutex internalCounterMtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsStackReadWriteMutex
|
class RsStackReadWriteMutex
|
||||||
|
Loading…
Reference in New Issue
Block a user