mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 09:09:17 +01:00
Implement ContextLock
Move-assignment operator
In certain cases the move constructor may not suffice and the move assignment operator is required, this commit implements that and moves to using a pointer for storing the `resource` member rather than a reference as its semantics matched what we desired more and allowed for assignment of the `resource`.
This commit is contained in:
parent
38d3ff4300
commit
d2a34b5f7a
@ -52,23 +52,30 @@ namespace skyline::gpu {
|
||||
template<typename T>
|
||||
class ContextLock {
|
||||
private:
|
||||
T &resource;
|
||||
T *resource;
|
||||
bool ownsLock; //!< If when this ContextLocked initially locked `resource`, it had never been locked for this context before
|
||||
|
||||
public:
|
||||
ContextLock(ContextTag tag, T &resource) : resource{resource}, ownsLock{resource.LockWithTag(tag)} {}
|
||||
ContextLock(ContextTag tag, T &resource) : resource{&resource}, ownsLock{resource.LockWithTag(tag)} {}
|
||||
|
||||
ContextLock(const ContextLock &) = delete;
|
||||
|
||||
ContextLock &operator=(const ContextLock &) = delete;
|
||||
|
||||
ContextLock(ContextLock &&other) noexcept : resource{other.resource}, ownsLock{other.ownsLock} {
|
||||
ContextLock(ContextLock &&other) : resource{other.resource}, ownsLock{other.ownsLock} {
|
||||
other.ownsLock = false;
|
||||
}
|
||||
|
||||
ContextLock &operator=(ContextLock &&other) {
|
||||
resource = other.resource;
|
||||
ownsLock = other.ownsLock;
|
||||
other.ownsLock = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~ContextLock() {
|
||||
if (ownsLock)
|
||||
resource.unlock();
|
||||
resource->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user