Skip to content

Commit

Permalink
ObjectLock can now be default constructed and assigned.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Nov 8, 2024
1 parent d255e13 commit c7b6564
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/concurrency/include/concurrency/ObjectLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ namespace l::concurrency {
template<class T>
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();
Expand All @@ -32,7 +43,7 @@ namespace l::concurrency {

protected:
std::unique_lock<std::mutex> mLock;
T* mObject;
T* mObject = nullptr;
};

}

0 comments on commit c7b6564

Please sign in to comment.