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

@ -111,7 +111,7 @@ AuthGPG::AuthGPG()
:p3Config(CONFIG_TYPE_AUTHGPG),gpgmeInit(false),gpgmeKeySelected(false) :p3Config(CONFIG_TYPE_AUTHGPG),gpgmeInit(false),gpgmeKeySelected(false)
{ {
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
gpgme_check_version(NULL); gpgme_check_version(NULL);
@ -219,7 +219,7 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
gpg_error_t ERR; gpg_error_t ERR;
/* XXX should check that CTX is valid */ /* XXX should check that CTX is valid */
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
if (!gpgmeInit) if (!gpgmeInit)
{ {
@ -278,7 +278,7 @@ int AuthGPG::GPGInit(std::string ownId)
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl; std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
if (!gpgmeInit) { if (!gpgmeInit) {
return 0; return 0;
@ -292,7 +292,7 @@ int AuthGPG::GPGInit(std::string ownId)
int lvl = 0; int lvl = 0;
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
if (mOwnGpgCert.id != mOwnGpgId) { if (mOwnGpgCert.id != mOwnGpgId) {
std::cerr << "AuthGPG::GPGInit() failed to find your id." << std::endl; std::cerr << "AuthGPG::GPGInit() failed to find your id." << std::endl;
return 0; return 0;
@ -336,7 +336,7 @@ bool AuthGPG::storeAllKeys_locked()
std::list<std::string> gpg_change_trust_list; std::list<std::string> gpg_change_trust_list;
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); RsStackMutex stack(gpgMtx);
gpg_error_t ERR; gpg_error_t ERR;
if (!gpgmeInit) if (!gpgmeInit)
@ -654,7 +654,7 @@ bool AuthGPG::printOwnKeys_locked()
bool AuthGPG::printKeys() bool AuthGPG::printKeys()
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
printAllKeys_locked(); printAllKeys_locked();
return printOwnKeys_locked(); return printOwnKeys_locked();
} }
@ -702,7 +702,7 @@ void print_pgpme_verify_summary(unsigned int summary)
bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl) bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl)
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
/* setup signers */ /* setup signers */
gpgme_signers_clear(CTX); gpgme_signers_clear(CTX);
if (GPG_ERR_NO_ERROR != gpgme_signers_add(CTX, mOwnGpgCert.key)) if (GPG_ERR_NO_ERROR != gpgme_signers_add(CTX, mOwnGpgCert.key))
@ -797,7 +797,7 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
std::cerr << "VerifySignature: datalen: " << datalen << " siglen: " << siglen << std::endl; std::cerr << "VerifySignature: datalen: " << datalen << " siglen: " << siglen << std::endl;
#endif #endif
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
if(!(gpgmeInit || gpgmeKeySelected)) if(!(gpgmeInit || gpgmeKeySelected))
return false ; return false ;
@ -889,14 +889,14 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
bool AuthGPG::active() bool AuthGPG::active()
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
return ((gpgmeInit) && (gpgmeKeySelected)); return ((gpgmeInit) && (gpgmeKeySelected));
} }
bool AuthGPG::GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) { bool AuthGPG::GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
gpgme_key_t newKey; gpgme_key_t newKey;
gpgme_genkey_result_t result; gpgme_genkey_result_t result;
@ -932,7 +932,7 @@ std::string AuthGPG::getGPGName(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) if (mKeyList.end() != (it = mKeyList.find(id)))
@ -946,7 +946,7 @@ std::string AuthGPG::getGPGEmail(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) if (mKeyList.end() != (it = mKeyList.find(id)))
@ -959,20 +959,20 @@ std::string AuthGPG::getGPGEmail(GPG_id id)
std::string AuthGPG::getGPGOwnId() std::string AuthGPG::getGPGOwnId()
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
return mOwnGpgId; return mOwnGpgId;
} }
std::string AuthGPG::getGPGOwnName() std::string AuthGPG::getGPGOwnName()
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
return mOwnGpgCert.name; return mOwnGpgCert.name;
} }
bool AuthGPG::getGPGAllList(std::list<std::string> &ids) bool AuthGPG::getGPGAllList(std::list<std::string> &ids)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
/* add an id for each pgp certificate */ /* add an id for each pgp certificate */
certmap::iterator it; certmap::iterator it;
@ -990,7 +990,7 @@ bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
#endif #endif
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
/* add an id for each pgp certificate */ /* add an id for each pgp certificate */
certmap::iterator it; certmap::iterator it;
@ -1029,7 +1029,7 @@ bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
} }
bool AuthGPG::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) { bool AuthGPG::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
gpgme_set_armor (CTX, 1); gpgme_set_armor (CTX, 1);
gpg_error_t ERR; gpg_error_t ERR;
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN))) if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN)))
@ -1043,7 +1043,7 @@ bool AuthGPG::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
} }
bool AuthGPG::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) { bool AuthGPG::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t(); gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t();
gpgme_key_t keys[2] = {mOwnGpgCert.key, NULL}; gpgme_key_t keys[2] = {mOwnGpgCert.key, NULL};
gpgme_set_armor (CTX, 1); gpgme_set_armor (CTX, 1);
@ -1061,7 +1061,7 @@ bool AuthGPG::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
bool AuthGPG::getGPGValidList(std::list<std::string> &ids) bool AuthGPG::getGPGValidList(std::list<std::string> &ids)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
/* add an id for each pgp certificate */ /* add an id for each pgp certificate */
certmap::iterator it; certmap::iterator it;
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
@ -1076,7 +1076,7 @@ bool AuthGPG::getGPGValidList(std::list<std::string> &ids)
bool AuthGPG::getGPGAcceptedList(std::list<std::string> &ids) bool AuthGPG::getGPGAcceptedList(std::list<std::string> &ids)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
{ {
@ -1091,7 +1091,7 @@ bool AuthGPG::getGPGAcceptedList(std::list<std::string> &ids)
bool AuthGPG::getGPGSignedList(std::list<std::string> &ids) bool AuthGPG::getGPGSignedList(std::list<std::string> &ids)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
{ {
@ -1106,7 +1106,7 @@ bool AuthGPG::getGPGSignedList(std::list<std::string> &ids)
bool AuthGPG::isGPGValid(GPG_id id) bool AuthGPG::isGPGValid(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) { if (mKeyList.end() != (it = mKeyList.find(id))) {
return (it->second.validLvl >= GPGME_VALIDITY_MARGINAL); return (it->second.validLvl >= GPGME_VALIDITY_MARGINAL);
@ -1119,7 +1119,7 @@ bool AuthGPG::isGPGValid(GPG_id id)
bool AuthGPG::isGPGId(GPG_id id) bool AuthGPG::isGPGId(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) { if (mKeyList.end() != (it = mKeyList.find(id))) {
return true; return true;
@ -1132,7 +1132,7 @@ bool AuthGPG::isGPGId(GPG_id id)
bool AuthGPG::isGPGSigned(GPG_id id) bool AuthGPG::isGPGSigned(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) if (mKeyList.end() != (it = mKeyList.find(id)))
{ {
@ -1144,7 +1144,7 @@ bool AuthGPG::isGPGSigned(GPG_id id)
bool AuthGPG::isGPGAccepted(GPG_id id) bool AuthGPG::isGPGAccepted(GPG_id id)
{ {
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) if (mKeyList.end() != (it = mKeyList.find(id)))
{ {
@ -1172,7 +1172,7 @@ std::string AuthGPG::SaveCertificateToString(std::string id)
} }
storeAllKeys_timed(); storeAllKeys_timed();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
std::string tmp; std::string tmp;
const char *pattern[] = { NULL, NULL }; const char *pattern[] = { NULL, NULL };
@ -1226,7 +1226,7 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
std::string fingerprint; std::string fingerprint;
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
//std::string cleancert = cleanUpCertificate(str); disable for p3disc message on windows system. Move the clean cert in p3peers //std::string cleancert = cleanUpCertificate(str); disable for p3disc message on windows system. Move the clean cert in p3peers
std::string cleancert = str; std::string cleancert = str;
@ -1278,7 +1278,7 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
//retrieve the id of the key //retrieve the id of the key
certmap::iterator it; certmap::iterator it;
gpg_id = "" ; gpg_id = "" ;
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
{ {
if (it->second.fpr == fingerprint) if (it->second.fpr == fingerprint)
@ -1321,7 +1321,7 @@ bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptan
/* reload stuff now ... */ /* reload stuff now ... */
storeAllKeys_locked(); storeAllKeys_locked();
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); RsStackMutex stack(gpgMtx);
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() == (it = mKeyList.find(gpg_id))) { if (mKeyList.end() == (it = mKeyList.find(gpg_id))) {
return false; return false;
@ -1357,7 +1357,7 @@ bool AuthGPG::SignCertificateLevel0(GPG_id id)
bool AuthGPG::RevokeCertificate(std::string id) bool AuthGPG::RevokeCertificate(std::string id)
{ {
//RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ //RsStackMutex stack(gpgMtx); /******* LOCKED ******/
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
std::cerr << "AuthGPG::RevokeCertificate(" << id << ") not implemented yet" << std::endl; std::cerr << "AuthGPG::RevokeCertificate(" << id << ") not implemented yet" << std::endl;
@ -1417,7 +1417,7 @@ int AuthGPG::privateSignCertificate(std::string id)
* Once the key is signed, it moves from Others to Peers list ??? * Once the key is signed, it moves from Others to Peers list ???
*/ */
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() == (it = mKeyList.find(id))) if (mKeyList.end() == (it = mKeyList.find(id)))
@ -1453,7 +1453,7 @@ int AuthGPG::privateSignCertificate(std::string id)
/* revoke the signature on Certificate */ /* revoke the signature on Certificate */
int AuthGPG::privateRevokeCertificate(std::string id) int AuthGPG::privateRevokeCertificate(std::string id)
{ {
//RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ //RsStackMutex stack(gpgMtx); /******* LOCKED ******/
return 0; return 0;
} }
@ -1467,7 +1467,7 @@ int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
} }
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); RsStackMutex stack(gpgMtx);
gpgcert trustCert = mKeyList.find(id)->second; gpgcert trustCert = mKeyList.find(id)->second;
gpgme_key_t trustKey = trustCert.key; gpgme_key_t trustKey = trustCert.key;
@ -2153,7 +2153,7 @@ std::list<RsItem*> AuthGPG::saveList(bool& cleanup)
std::cerr << "AuthGPG::saveList() called" << std::endl ; std::cerr << "AuthGPG::saveList() called" << std::endl ;
#endif #endif
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
cleanup = true ; cleanup = true ;
std::list<RsItem*> lst ; std::list<RsItem*> lst ;
@ -2187,7 +2187,7 @@ bool AuthGPG::loadList(std::list<RsItem*> load)
storeAllKeys_locked(); storeAllKeys_locked();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackMutex stack(gpgMtx); /******* LOCKED ******/
/* load the list of accepted gpg keys */ /* load the list of accepted gpg keys */
std::list<RsItem *>::iterator it; std::list<RsItem *>::iterator it;
for(it = load.begin(); it != load.end(); it++) { for(it = load.begin(); it != load.end(); it++) {

View file

@ -244,7 +244,7 @@ private:
static AuthGPG *instance_gpg; // pointeur vers le singleton static AuthGPG *instance_gpg; // pointeur vers le singleton
RsReadWriteMutex pgpMtx; RsMutex gpgMtx;
/* Below is protected via the mutex */ /* Below is protected via the mutex */
certmap mKeyList; certmap mKeyList;

View file

@ -151,49 +151,50 @@ void RsQueueThread::run()
} }
} }
RsReadWriteMutex::RsReadWriteMutex():readLocks(0) { // maybe we can use it again
} //RsReadWriteMutex::RsReadWriteMutex():readLocks(0) {
//}
void RsReadWriteMutex::readLock() { //
internalCounterMtx.lock();//lock internal read counter //void RsReadWriteMutex::readLock() {
if (readLocks == 0) { // internalCounterMtx.lock();//lock internal read counter
lock(); //lock normal mutex // if (readLocks == 0) {
} // lock(); //lock normal mutex
readLocks++; // }
internalCounterMtx.unlock(); // readLocks++;
} // internalCounterMtx.unlock();
//}
void RsReadWriteMutex::readUnlock() { //
internalCounterMtx.lock();//lock internal read counter //void RsReadWriteMutex::readUnlock() {
if (readLocks == 1) { // internalCounterMtx.lock();//lock internal read counter
unlock(); // if (readLocks == 1) {
} // unlock();
if (readLocks != 0) { // }
readLocks--; // if (readLocks != 0) {
} // readLocks--;
internalCounterMtx.unlock(); // }
} // internalCounterMtx.unlock();
//}
void RsReadWriteMutex::writeLock() { //
lock(); //void RsReadWriteMutex::writeLock() {
} // lock();
//}
void RsReadWriteMutex::writeUnlock() { //
unlock(); //void RsReadWriteMutex::writeUnlock() {
} // unlock();
//}
void RsReadWriteMutex::rwlock(uint32_t type) { //
if (type & READ_LOCK) { //void RsReadWriteMutex::rwlock(uint32_t type) {
readLock(); // if (type & READ_LOCK) {
} else { // readLock();
writeLock(); // } else {
} // writeLock();
} // }
//}
void RsReadWriteMutex::rwunlock(uint32_t type) { //
if (type & READ_LOCK) { //void RsReadWriteMutex::rwunlock(uint32_t type) {
readUnlock(); // if (type & READ_LOCK) {
} else { // readUnlock();
writeUnlock(); // } else {
} // writeUnlock();
} // }
//}

View file

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