diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-08 21:17:27 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-08 21:17:27 +0000 |
commit | dae38cdf2f8bd74de485130c3fe63fb91729fce1 (patch) | |
tree | e414bc66981ac0dc85f348161217c8dec231691c /storage/src/tests/persistence/common/persistenceproviderwrapper.h | |
parent | 8eec2e8a69d68875ef0ecb3486cf59eeed371dee (diff) |
Use a lock to ensure it is thread safe.
Diffstat (limited to 'storage/src/tests/persistence/common/persistenceproviderwrapper.h')
-rw-r--r-- | storage/src/tests/persistence/common/persistenceproviderwrapper.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/storage/src/tests/persistence/common/persistenceproviderwrapper.h b/storage/src/tests/persistence/common/persistenceproviderwrapper.h index 9ca08becabe..059bb4dea00 100644 --- a/storage/src/tests/persistence/common/persistenceproviderwrapper.h +++ b/storage/src/tests/persistence/common/persistenceproviderwrapper.h @@ -19,6 +19,7 @@ #include <vespa/persistence/spi/abstractpersistenceprovider.h> #include <vector> #include <string> +#include <mutex> namespace storage { @@ -50,8 +51,10 @@ public: private: spi::PersistenceProvider& _spi; spi::Result _result; + mutable std::mutex _lock; mutable std::vector<std::string> _log; uint32_t _failureMask; + using Guard = std::unique_lock<std::mutex>; public: PersistenceProviderWrapper(spi::PersistenceProvider& spi); ~PersistenceProviderWrapper() override; @@ -61,12 +64,16 @@ public: * return the given error without the wrapped SPI ever being invoked. */ void setResult(const spi::Result& result) { + Guard guard(_lock); _result = result; } void clearResult() { _result = spi::Result(spi::Result::ErrorType::NONE, ""); } - const spi::Result& getResult() const { return _result; } + spi::Result getResult() const { + Guard guard(_lock); + return _result; + } /** * Set a mask for operations to fail with _result */ @@ -81,8 +88,10 @@ public: /** * Clear log of all operations performed. */ - void clearOperationLog() { _log.clear(); } - const std::vector<std::string>& getOperationLog() const { return _log; } + void clearOperationLog() { + Guard guard(_lock); + _log.clear(); + } spi::Result createBucket(const spi::Bucket&, spi::Context&) override; spi::PartitionStateListResult getPartitionStates() const override; |