Mercurial > hg > orthanc-databases
changeset 231:0a9b48d19643
removed mutex out of DatabaseManager
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Apr 2021 11:59:31 +0200 |
parents | 675f8322eb7c |
children | 4e15eace9b90 |
files | Framework/Common/DatabaseManager.cpp Framework/Common/DatabaseManager.h Framework/Plugins/StorageBackend.cpp Framework/Plugins/StorageBackend.h |
diffstat | 4 files changed, 19 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp Tue Apr 06 11:17:00 2021 +0200 +++ b/Framework/Common/DatabaseManager.cpp Tue Apr 06 11:59:31 2021 +0200 @@ -164,8 +164,6 @@ void DatabaseManager::StartTransaction(TransactionType type) { - boost::recursive_mutex::scoped_lock lock(mutex_); - try { if (transaction_.get() != NULL) @@ -186,8 +184,6 @@ void DatabaseManager::CommitTransaction() { - boost::recursive_mutex::scoped_lock lock(mutex_); - if (transaction_.get() == NULL) { LOG(ERROR) << "Cannot commit a non-existing transaction"; @@ -211,8 +207,6 @@ void DatabaseManager::RollbackTransaction() { - boost::recursive_mutex::scoped_lock lock(mutex_); - if (transaction_.get() == NULL) { LOG(ERROR) << "Cannot rollback a non-existing transaction"; @@ -236,7 +230,6 @@ DatabaseManager::Transaction::Transaction(DatabaseManager& manager, TransactionType type) : - lock_(manager.mutex_), manager_(manager), database_(manager.GetDatabase()), committed_(false) @@ -328,7 +321,6 @@ DatabaseManager::StatementBase::StatementBase(DatabaseManager& manager) : manager_(manager), - lock_(manager_.mutex_), transaction_(manager_.GetTransaction()) { }
--- a/Framework/Common/DatabaseManager.h Tue Apr 06 11:17:00 2021 +0200 +++ b/Framework/Common/DatabaseManager.h Tue Apr 06 11:59:31 2021 +0200 @@ -27,18 +27,21 @@ #include <Compatibility.h> // For std::unique_ptr<> #include <Enumerations.h> -#include <boost/thread/recursive_mutex.hpp> #include <memory> namespace OrthancDatabases { + /** + * WARNING: In PostgreSQL releases <= 3.3 and in MySQL releases <= + * 3.0, this class was protected by a mutex. It is now assumed that + * locking must be implemented at a higher level. + **/ class DatabaseManager : public boost::noncopyable { private: typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; - boost::recursive_mutex mutex_; std::unique_ptr<IDatabase> database_; std::unique_ptr<ITransaction> transaction_; CachedStatements cachedStatements_; @@ -86,10 +89,9 @@ class Transaction : public boost::noncopyable { private: - boost::recursive_mutex::scoped_lock lock_; - DatabaseManager& manager_; - IDatabase& database_; - bool committed_; + DatabaseManager& manager_; + IDatabase& database_; + bool committed_; public: explicit Transaction(DatabaseManager& manager, @@ -114,11 +116,10 @@ class StatementBase : public boost::noncopyable { private: - DatabaseManager& manager_; - boost::recursive_mutex::scoped_lock lock_; - ITransaction& transaction_; - std::unique_ptr<Query> query_; - std::unique_ptr<IResult> result_; + DatabaseManager& manager_; + ITransaction& transaction_; + std::unique_ptr<Query> query_; + std::unique_ptr<IResult> result_; IResult& GetResult() const;
--- a/Framework/Plugins/StorageBackend.cpp Tue Apr 06 11:17:00 2021 +0200 +++ b/Framework/Plugins/StorageBackend.cpp Tue Apr 06 11:59:31 2021 +0200 @@ -31,6 +31,7 @@ #include <Compatibility.h> // For std::unique_ptr<> #include <OrthancException.h> +#include <cassert> #include <limits>
--- a/Framework/Plugins/StorageBackend.h Tue Apr 06 11:17:00 2021 +0200 +++ b/Framework/Plugins/StorageBackend.h Tue Apr 06 11:59:31 2021 +0200 @@ -25,12 +25,15 @@ #include <orthanc/OrthancCDatabasePlugin.h> +#include <boost/thread/mutex.hpp> + namespace OrthancDatabases { class StorageBackend : public boost::noncopyable { private: + boost::mutex mutex_; std::unique_ptr<DatabaseManager> manager_; DatabaseManager& GetManager(); @@ -54,10 +57,12 @@ class Accessor : public boost::noncopyable { private: - DatabaseManager& manager_; + boost::mutex::scoped_lock lock_; + DatabaseManager& manager_; public: Accessor(StorageBackend& backend) : + lock_(backend.mutex_), manager_(backend.GetManager()) { }