Remove copy constructor/assignment from utils::SpinLock
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2581
This commit is contained in:
parent
0d979dd7b3
commit
9cc204793d
@ -28,6 +28,28 @@ class SpinLock {
|
|||||||
<< "Couldn't construct utils::SpinLock!";
|
<< "Couldn't construct utils::SpinLock!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpinLock(SpinLock &&other) noexcept : lock_(other.lock_) {
|
||||||
|
CHECK(pthread_spin_init(&other.lock_, PTHREAD_PROCESS_PRIVATE) == 0)
|
||||||
|
<< "Couldn't construct utils::SpinLock!";
|
||||||
|
}
|
||||||
|
|
||||||
|
SpinLock &operator=(SpinLock &&other) noexcept {
|
||||||
|
CHECK(pthread_spin_destroy(&lock_) == 0)
|
||||||
|
<< "Couldn't destruct utils::SpinLock!";
|
||||||
|
lock_ = other.lock_;
|
||||||
|
CHECK(pthread_spin_init(&other.lock_, PTHREAD_PROCESS_PRIVATE) == 0)
|
||||||
|
<< "Couldn't construct utils::SpinLock!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpinLock(const SpinLock &) = delete;
|
||||||
|
SpinLock &operator=(const SpinLock &) = delete;
|
||||||
|
|
||||||
|
~SpinLock() {
|
||||||
|
CHECK(pthread_spin_destroy(&lock_) == 0)
|
||||||
|
<< "Couldn't destruct utils::SpinLock!";
|
||||||
|
}
|
||||||
|
|
||||||
void lock() {
|
void lock() {
|
||||||
// `pthread_spin_lock` returns -1 only when there is a deadlock detected
|
// `pthread_spin_lock` returns -1 only when there is a deadlock detected
|
||||||
// (errno EDEADLOCK).
|
// (errno EDEADLOCK).
|
||||||
@ -47,11 +69,6 @@ class SpinLock {
|
|||||||
<< "Couldn't unlock utils::SpinLock!";
|
<< "Couldn't unlock utils::SpinLock!";
|
||||||
}
|
}
|
||||||
|
|
||||||
~SpinLock() {
|
|
||||||
CHECK(pthread_spin_destroy(&lock_) == 0)
|
|
||||||
<< "Couldn't destruct utils::SpinLock!";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_spinlock_t lock_;
|
pthread_spinlock_t lock_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user