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; }; }