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:
Matej Ferencevic 2019-12-04 13:26:21 +01:00
parent 0d979dd7b3
commit 9cc204793d

View File

@ -28,6 +28,28 @@ class 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() {
// `pthread_spin_lock` returns -1 only when there is a deadlock detected
// (errno EDEADLOCK).
@ -47,11 +69,6 @@ class SpinLock {
<< "Couldn't unlock utils::SpinLock!";
}
~SpinLock() {
CHECK(pthread_spin_destroy(&lock_) == 0)
<< "Couldn't destruct utils::SpinLock!";
}
private:
pthread_spinlock_t lock_;
};