fixed crash (asserts) by parallel calls to gpg.exe

changed the RsReadWriteMutex to RsStackMutex in AuthGPG


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3158 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-06-18 20:19:04 +00:00
parent 73ae89acad
commit ec6c252d62
4 changed files with 118 additions and 116 deletions

View file

@ -151,49 +151,50 @@ 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();
}
}
// maybe we can use it again
//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();
// }
//}

View file

@ -102,40 +102,41 @@ class RsStackMutex
RsMutex &mMtx;
};
class RsReadWriteMutex: public RsMutex
{
public:
RsReadWriteMutex();
void readLock();
void readUnlock();
void writeLock();
void writeUnlock();
void rwlock(uint32_t type);
void rwunlock(uint32_t type);
const static uint32_t READ_LOCK = 0x0001;
const static uint32_t WRITE_LOCK = 0x0002;
private:
int readLocks;
RsMutex internalCounterMtx;
};
class RsStackReadWriteMutex
{
public:
RsStackReadWriteMutex(RsReadWriteMutex &mtx): mMtx(mtx) { mMtx.writeLock(); writeLock = true;}
RsStackReadWriteMutex(RsReadWriteMutex &mtx, uint32_t type): mMtx(mtx) { if (type == RsReadWriteMutex::READ_LOCK) {mMtx.readLock(); writeLock = false;} else {mMtx.writeLock(); writeLock = true;} }
~RsStackReadWriteMutex() { if(writeLock) {mMtx.writeUnlock();} else {mMtx.readUnlock();} }
private:
RsReadWriteMutex &mMtx;
bool writeLock;
};
// maybe we can use it again
//class RsReadWriteMutex: public RsMutex
//{
// public:
// RsReadWriteMutex();
//
// void readLock();
// void readUnlock();
// void writeLock();
// void writeUnlock();
//
// void rwlock(uint32_t type);
// void rwunlock(uint32_t type);
//
// const static uint32_t READ_LOCK = 0x0001;
// const static uint32_t WRITE_LOCK = 0x0002;
//
//
// private:
// int readLocks;
// RsMutex internalCounterMtx;
//};
//
//class RsStackReadWriteMutex
//{
// public:
//
// RsStackReadWriteMutex(RsReadWriteMutex &mtx): mMtx(mtx) { mMtx.writeLock(); writeLock = true;}
// RsStackReadWriteMutex(RsReadWriteMutex &mtx, uint32_t type): mMtx(mtx) { if (type == RsReadWriteMutex::READ_LOCK) {mMtx.readLock(); writeLock = false;} else {mMtx.writeLock(); writeLock = true;} }
// ~RsStackReadWriteMutex() { if(writeLock) {mMtx.writeUnlock();} else {mMtx.readUnlock();} }
//
// private:
// RsReadWriteMutex &mMtx;
// bool writeLock;
//};
class RsThread;