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:
PixelyIon 2022-07-19 22:39:14 +05:30
parent 38d3ff4300
commit d2a34b5f7a
No known key found for this signature in database
GPG Key ID: 11BC6C3201BC2C05

View File

@ -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();
}
/**