From 9cc204793d515c5818f61161c62b34a2c25160a0 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Wed, 4 Dec 2019 13:26:21 +0100 Subject: [PATCH] Remove copy constructor/assignment from utils::SpinLock Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2581 --- src/utils/spin_lock.hpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/utils/spin_lock.hpp b/src/utils/spin_lock.hpp index 967aba27d..e40210310 100644 --- a/src/utils/spin_lock.hpp +++ b/src/utils/spin_lock.hpp @@ -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_; };