mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
threading: rename CSemaphore methods to match std::semaphore
This commit is contained in:
@@ -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<const std::byte> 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<const std::byte> 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<DatabaseCursor> SQLiteBatch::GetNewPrefixCursor(std::span<const
|
||||
bool SQLiteBatch::TxnBegin()
|
||||
{
|
||||
if (!m_database.m_db || m_txn) return false;
|
||||
m_database.m_write_semaphore.wait();
|
||||
m_database.m_write_semaphore.acquire();
|
||||
Assert(!m_database.HasActiveTxn());
|
||||
int res = Assert(m_exec_handler)->Exec(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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user