diff --git a/src/net.cpp b/src/net.cpp index 66ded1041cd..b78eb749b3b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3428,13 +3428,13 @@ void CConnman::Interrupt() if (semOutbound) { for (int i=0; ipost(); + semOutbound->release(); } } if (semAddnode) { for (int i=0; ipost(); + semAddnode->release(); } } } diff --git a/src/sync.h b/src/sync.h index b22956ef1ab..749a368516b 100644 --- a/src/sync.h +++ b/src/sync.h @@ -321,14 +321,14 @@ public: CSemaphore& operator=(const CSemaphore&) = delete; CSemaphore& operator=(CSemaphore&&) = delete; - void wait() noexcept + void acquire() noexcept { std::unique_lock lock(mutex); condition.wait(lock, [&]() { return value >= 1; }); value--; } - bool try_wait() noexcept + bool try_acquire() noexcept { std::lock_guard lock(mutex); if (value < 1) { @@ -338,7 +338,7 @@ public: return true; } - void post() noexcept + void release() noexcept { { std::lock_guard lock(mutex); @@ -361,7 +361,7 @@ public: if (fHaveGrant) { return; } - sem->wait(); + sem->acquire(); fHaveGrant = true; } @@ -370,13 +370,13 @@ public: if (!fHaveGrant) { return; } - sem->post(); + sem->release(); fHaveGrant = false; } bool TryAcquire() noexcept { - if (!fHaveGrant && sem->try_wait()) { + if (!fHaveGrant && sem->try_acquire()) { fHaveGrant = true; } return fHaveGrant; diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index 49096c91aa3..9b6215f9371 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -445,7 +445,7 @@ void SQLiteBatch::Close() try { m_database.Open(); // If TxnAbort failed and we refreshed the connection, the semaphore was not released, so release it here to avoid deadlocks on future writes. - m_database.m_write_semaphore.post(); + m_database.m_write_semaphore.release(); } catch (const std::runtime_error&) { // If open fails, cleanup this object and rethrow the exception m_database.Close(); @@ -498,7 +498,7 @@ bool SQLiteBatch::WriteKey(DataStream&& key, DataStream&& value, bool overwrite) if (!BindBlobToStatement(stmt, 2, value, "value")) return false; // Acquire semaphore if not previously acquired when creating a transaction. - if (!m_txn) m_database.m_write_semaphore.wait(); + if (!m_txn) m_database.m_write_semaphore.acquire(); // Execute int res = sqlite3_step(stmt); @@ -508,7 +508,7 @@ bool SQLiteBatch::WriteKey(DataStream&& key, DataStream&& value, bool overwrite) LogPrintf("%s: Unable to execute statement: %s\n", __func__, sqlite3_errstr(res)); } - if (!m_txn) m_database.m_write_semaphore.post(); + if (!m_txn) m_database.m_write_semaphore.release(); return res == SQLITE_DONE; } @@ -522,7 +522,7 @@ bool SQLiteBatch::ExecStatement(sqlite3_stmt* stmt, std::span b if (!BindBlobToStatement(stmt, 1, blob, "key")) return false; // Acquire semaphore if not previously acquired when creating a transaction. - if (!m_txn) m_database.m_write_semaphore.wait(); + if (!m_txn) m_database.m_write_semaphore.acquire(); // Execute int res = sqlite3_step(stmt); @@ -532,7 +532,7 @@ bool SQLiteBatch::ExecStatement(sqlite3_stmt* stmt, std::span b LogPrintf("%s: Unable to execute statement: %s\n", __func__, sqlite3_errstr(res)); } - if (!m_txn) m_database.m_write_semaphore.post(); + if (!m_txn) m_database.m_write_semaphore.release(); return res == SQLITE_DONE; } @@ -651,12 +651,12 @@ std::unique_ptr SQLiteBatch::GetNewPrefixCursor(std::spanExec(m_database, "BEGIN TRANSACTION"); if (res != SQLITE_OK) { LogPrintf("SQLiteBatch: Failed to begin the transaction\n"); - m_database.m_write_semaphore.post(); + m_database.m_write_semaphore.release(); } else { m_txn = true; } @@ -672,7 +672,7 @@ bool SQLiteBatch::TxnCommit() LogPrintf("SQLiteBatch: Failed to commit the transaction\n"); } else { m_txn = false; - m_database.m_write_semaphore.post(); + m_database.m_write_semaphore.release(); } return res == SQLITE_OK; } @@ -686,7 +686,7 @@ bool SQLiteBatch::TxnAbort() LogPrintf("SQLiteBatch: Failed to abort the transaction\n"); } else { m_txn = false; - m_database.m_write_semaphore.post(); + m_database.m_write_semaphore.release(); } return res == SQLITE_OK; }