From c7b65643a9d3336c35f4eac7c49e0382cdf729d3 Mon Sep 17 00:00:00 2001 From: lnd3 Date: Fri, 8 Nov 2024 07:45:15 +0100 Subject: [PATCH] ObjectLock can now be default constructed and assigned. --- .../concurrency/include/concurrency/ObjectLock.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/concurrency/include/concurrency/ObjectLock.h b/packages/concurrency/include/concurrency/ObjectLock.h index 94040243..3dda0b71 100644 --- a/packages/concurrency/include/concurrency/ObjectLock.h +++ b/packages/concurrency/include/concurrency/ObjectLock.h @@ -7,12 +7,23 @@ namespace l::concurrency { template class ObjectLock { public: + ObjectLock() = default; ObjectLock(std::mutex& mutex, T* object) : mLock(mutex, std::adopt_lock), mObject(object) {} + ~ObjectLock() = default; + ObjectLock& operator=(ObjectLock&& other) { + if (this != &other) { + mLock = std::move(other.mLock); + mObject = other.mObject; + other.mObject = nullptr; + } + return *this; + } + void reset() { mObject = nullptr; mLock.unlock(); @@ -32,7 +43,7 @@ namespace l::concurrency { protected: std::unique_lock mLock; - T* mObject; + T* mObject = nullptr; }; }