mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update mutex locks to prevent mutex dead lock
This commit is contained in:
parent
f01bed64dc
commit
16dcc25960
@ -13,10 +13,11 @@ CronManager::CronManager()
|
||||
|
||||
CronManager::~CronManager()
|
||||
{
|
||||
mMainWorkMutex.lock();
|
||||
Poco::ScopedLock<Poco::FastMutex> _lock(mMainWorkMutex);
|
||||
|
||||
mMainTimer.stop();
|
||||
mInitalized = false;
|
||||
mMainWorkMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
CronManager* CronManager::getInstance()
|
||||
@ -52,7 +53,6 @@ void CronManager::runUpdateStep(Poco::Timer& timer)
|
||||
//printf("%s [CronManager::runUpdateStep] \n", Poco::DateTimeFormatter::format(current, "%d.%m.%y %H:%M:%S.%i").data());
|
||||
Poco::ScopedLock<Poco::FastMutex> _lock(mMainWorkMutex);
|
||||
if (!mInitalized) {
|
||||
mMainWorkMutex.unlock();
|
||||
return;
|
||||
}
|
||||
mNodeServersToPingMutex.lock();
|
||||
@ -85,7 +85,7 @@ void CronManager::runUpdateStep(Poco::Timer& timer)
|
||||
//mMainTimer.restart(mDefaultIntervalMilliseconds);
|
||||
}
|
||||
}
|
||||
mTimestampsMutex.unlock();
|
||||
mTimestampsMutex.unlock();
|
||||
//printf("[CronManager::runUpdateStep] end\n");
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,8 @@ ErrorManager::~ErrorManager()
|
||||
void ErrorManager::addError(Notification* error, bool log/* = true*/)
|
||||
{
|
||||
DHASH id = DRMakeStringHash(error->getFunctionName());
|
||||
mWorkingMutex.lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkingMutex);
|
||||
|
||||
auto it = mErrorsMap.find(id);
|
||||
std::list<Notification*>* list = nullptr;
|
||||
|
||||
@ -52,13 +53,12 @@ void ErrorManager::addError(Notification* error, bool log/* = true*/)
|
||||
list = it->second;
|
||||
// check if hash collision
|
||||
if (strcmp((*list->begin())->getFunctionName(), error->getFunctionName()) != 0) {
|
||||
mWorkingMutex.unlock();
|
||||
|
||||
throw "[ErrorManager::addError] hash collision detected";
|
||||
}
|
||||
}
|
||||
list->push_back(error);
|
||||
|
||||
mWorkingMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -84,30 +84,29 @@ MemoryPageStack::~MemoryPageStack()
|
||||
|
||||
MemoryBin* MemoryPageStack::getFreeMemory()
|
||||
{
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
if (!mSize) {
|
||||
unlock();
|
||||
return nullptr;
|
||||
}
|
||||
if (mMemoryBinStack.size() == 0) {
|
||||
unlock();
|
||||
return new MemoryBin(mSize);
|
||||
}
|
||||
MemoryBin* memoryBin = mMemoryBinStack.top();
|
||||
mMemoryBinStack.pop();
|
||||
unlock();
|
||||
|
||||
return memoryBin;
|
||||
}
|
||||
void MemoryPageStack::releaseMemory(MemoryBin* memory)
|
||||
{
|
||||
if (!memory) return;
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
if (memory->size() != mSize) {
|
||||
unlock();
|
||||
throw new Poco::Exception("MemoryPageStack::releaseMemory wron memory page stack");
|
||||
}
|
||||
mMemoryBinStack.push(memory);
|
||||
unlock();
|
||||
|
||||
}
|
||||
|
||||
// ***********************************************************************************
|
||||
|
||||
@ -11,7 +11,7 @@ namespace model {
|
||||
|
||||
TransactionBody::~TransactionBody()
|
||||
{
|
||||
lock();
|
||||
lock("TransactionBody::~TransactionBody");
|
||||
if (mTransactionSpecific) {
|
||||
delete mTransactionSpecific;
|
||||
mTransactionSpecific = nullptr;
|
||||
|
||||
@ -40,7 +40,7 @@ namespace model {
|
||||
|
||||
static Poco::AutoPtr<TransactionBody> load(const std::string& protoMessageBin);
|
||||
|
||||
inline TransactionType getType() { lock(); auto t = mType; unlock(); return t; }
|
||||
inline TransactionType getType() { Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex); return mType; }
|
||||
std::string getMemo();
|
||||
void setMemo(const std::string& memo);
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ namespace model {
|
||||
|
||||
int TransactionTransfer::prepare()
|
||||
{
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
const static char functionName[] = { "TransactionTransfer::prepare" };
|
||||
|
||||
mKontoTable.reserve(2);
|
||||
@ -122,7 +122,6 @@ namespace model {
|
||||
//*/
|
||||
|
||||
mIsPrepared = true;
|
||||
unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -156,25 +155,21 @@ namespace model {
|
||||
|
||||
const std::string& TransactionTransfer::getKontoNameCell(int index)
|
||||
{
|
||||
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
if (index >= mKontoTable.size()) {
|
||||
unlock();
|
||||
return mInvalidIndexMessage;
|
||||
}
|
||||
unlock();
|
||||
|
||||
return mKontoTable[index].kontoNameCell;
|
||||
}
|
||||
|
||||
const std::string& TransactionTransfer::getAmountCell(int index)
|
||||
{
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
if (index >= mKontoTable.size()) {
|
||||
unlock();
|
||||
return mInvalidIndexMessage;
|
||||
}
|
||||
unlock();
|
||||
|
||||
return mKontoTable[index].amountCell;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ namespace model {
|
||||
int prepare();
|
||||
TransactionValidation validate();
|
||||
|
||||
inline size_t getKontoTableSize() { lock(); size_t s = mKontoTable.size(); unlock(); return s; }
|
||||
inline size_t getKontoTableSize() { Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex); return mKontoTable.size(); }
|
||||
const std::string& getKontoNameCell(int index);
|
||||
const std::string& getAmountCell(int index);
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ namespace model
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
|
||||
lock();
|
||||
lock("AppAccessToken::_insertIntoDB");
|
||||
assert(mUserId > 0);
|
||||
assert(mAccessCode > 0);
|
||||
|
||||
|
||||
@ -119,11 +119,11 @@ namespace model {
|
||||
Poco::Data::Statement CryptoKey::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where public_key = ?"
|
||||
, into(mID), use(mPublicKey);
|
||||
unlock();
|
||||
return select;
|
||||
}
|
||||
|
||||
@ -131,11 +131,10 @@ namespace model {
|
||||
Poco::Data::Statement CryptoKey::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (private_key, public_key, crypto_key_type_id) VALUES(?,?,?)"
|
||||
, use(mPrivateKey), use(mPublicKey), use(mKeyType);
|
||||
unlock();
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ namespace model {
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
|
||||
lock();
|
||||
lock("EmailOptIn::_insertIntoDB");
|
||||
assert(mUserId > 0);
|
||||
assert(mEmailVerificationCode > 0);
|
||||
|
||||
|
||||
@ -69,22 +69,24 @@ namespace model {
|
||||
Poco::Data::Statement Group::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where alias = ?"
|
||||
, into(mID), use(mAlias);
|
||||
unlock();
|
||||
|
||||
return select;
|
||||
|
||||
}
|
||||
Poco::Data::Statement Group::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (alias, name, url, home, description) VALUES(?,?,?,?,?)"
|
||||
, use(mAlias), use(mName), use(mUrl), use(mHome), use(mDescription);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,21 +110,23 @@ namespace model {
|
||||
Poco::Data::Statement HederaAccount::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where account_hedera_id = ?"
|
||||
, into(mID), use(mAccountHederaId);
|
||||
unlock();
|
||||
|
||||
return select;
|
||||
}
|
||||
Poco::Data::Statement HederaAccount::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (user_id, account_hedera_id, account_key_id, balance, network_type) VALUES(?,?,?,?,?)"
|
||||
, use(mUserId), use(mAccountHederaId), use(mAccountKeyId), use(mBalance), use(mType);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -77,21 +77,23 @@ namespace model {
|
||||
Poco::Data::Statement HederaId::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where shardNum = ? AND realmNum = ? AND num = ?"
|
||||
, into(mID), use(mShardNum), use(mRealmNum), use(mNum);
|
||||
unlock();
|
||||
|
||||
return select;
|
||||
}
|
||||
Poco::Data::Statement HederaId::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (shardNum, realmNum, num) VALUES(?,?,?)"
|
||||
, use(mShardNum), use(mRealmNum), use(mNum);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,24 +86,26 @@ namespace model {
|
||||
Poco::Data::Statement HederaTopic::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where topic_hedera_id = ? "
|
||||
<< " AND name = ? "
|
||||
, into(mID), use(mTopicHederaId), use(mName);
|
||||
unlock();
|
||||
|
||||
return select;
|
||||
}
|
||||
Poco::Data::Statement HederaTopic::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (topic_hedera_id, name, auto_renew_account_hedera_id, auto_renew_period,"
|
||||
<< " group_id, admin_key_id, submit_key_id, current_timeout, sequence_number) VALUES(?,?,?,?,?,?,?,?,?)"
|
||||
, use(mTopicHederaId), use(mName), use(mAutoRenewAccountHederaId), use(mAutoRenewPeriod)
|
||||
, use(mGroupId), use(mAdminKeyId), use(mSubmitKeyId), use(mCurrentTimeout), use(mSequenceNumber);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -186,7 +186,7 @@ namespace model {
|
||||
resultCount = select.execute();
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
lock();
|
||||
lock("ModelBase::loadFromDB");
|
||||
addError(new ParamError(getTableName(), "mysql error by multi selecting", ex.displayText().data()));
|
||||
addError(new ParamError(getTableName(), "field name for select: ", fieldName.data()));
|
||||
unlock();
|
||||
|
||||
@ -107,23 +107,24 @@ namespace model {
|
||||
Poco::Data::Statement NodeServer::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " where url = ? AND port = ? "
|
||||
, into(mID), use(mUrl), use(mPort);
|
||||
|
||||
unlock();
|
||||
return select;
|
||||
}
|
||||
|
||||
Poco::Data::Statement NodeServer::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (url, port, group_id, server_type, node_hedera_id) VALUES(?,?,?,?,?)"
|
||||
, use(mUrl), use(mPort), use(mGroupId), use(mServerType), use(mNodeHederaId);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -135,13 +135,14 @@ namespace model
|
||||
Poco::Data::Statement PendingTask::_loadIdFromDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
select << "SELECT id FROM " << getTableName()
|
||||
<< " WHERE user_id = ? "
|
||||
<< " AND TIMESTAMPDIFF(SECOND, created, ?) = 0 "
|
||||
<< " AND task_type_id = ? "
|
||||
, into(mID), use(mUserId), use(mCreated), use(mTaskTypeId);
|
||||
unlock();
|
||||
|
||||
return select;
|
||||
}
|
||||
|
||||
@ -149,11 +150,12 @@ namespace model
|
||||
Poco::Data::Statement PendingTask::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (user_id, hedera_id, request, created, task_type_id, child_pending_task_id, parent_pending_task_id) VALUES(?,?,?,?,?,?,?)"
|
||||
, use(mUserId), use(mHederaId), use(mRequest), use(mCreated), use(mTaskTypeId), use(mChildPendingTaskId), use(mParentPendingTaskId);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,12 +33,12 @@ namespace model {
|
||||
Poco::Data::Statement UserBackup::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
|
||||
lock();
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (user_id, passphrase, mnemonic_type) VALUES(?,?,?)"
|
||||
, use(mUserId), bind(mPassphrase), use(mMnemonicType);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -30,12 +30,12 @@ namespace model {
|
||||
Poco::Data::Statement UserRole::_insertIntoDB(Poco::Data::Session session)
|
||||
{
|
||||
Poco::Data::Statement insert(session);
|
||||
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
|
||||
|
||||
lock();
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (user_id, role_id) VALUES(?,?)"
|
||||
, use(mUserId), bind(mType);
|
||||
unlock();
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ namespace UniLib {
|
||||
{
|
||||
// look at pending tasks
|
||||
TaskPtr task;
|
||||
mPendingTasksMutex.lock();
|
||||
mPendingTasksMutex.lock("CPUSheduler::getNextUndoneTask");
|
||||
for (std::list<TaskPtr>::iterator it = mPendingTasks.begin(); it != mPendingTasks.end(); it++) {
|
||||
if ((*it)->isAllParentsReady()) {
|
||||
task = *it;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user