From 747cfa9237fa7b2848e93e50f15df80cabb97fe5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 24 May 2019 11:47:19 +1000 Subject: [PATCH] thread/spinlock: don't try to lock during a move operation --- thread/spinlock.cpp | 7 ------- thread/spinlock.hpp | 14 +++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/thread/spinlock.cpp b/thread/spinlock.cpp index 027dbbd2..93cd176d 100644 --- a/thread/spinlock.cpp +++ b/thread/spinlock.cpp @@ -30,14 +30,7 @@ spinlock::spinlock (spinlock &&rhs) noexcept: //----------------------------------------------------------------------------- spinlock& spinlock::operator= (spinlock &&rhs) noexcept { - lock (); - rhs.lock (); - held = rhs.held.load (); - - rhs.unlock (); - unlock (); - return *this; } diff --git a/thread/spinlock.hpp b/thread/spinlock.hpp index e8a93656..2d6a14e5 100644 --- a/thread/spinlock.hpp +++ b/thread/spinlock.hpp @@ -3,22 +3,24 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2018 Danny Robson + * Copyright 2018-2019 Danny Robson */ -#ifndef CRUFT_UTIL_THREAD_SPINLOCK_HPP -#define CRUFT_UTIL_THREAD_SPINLOCK_HPP +#pragma once #include namespace cruft::thread { - /// a CPU intensive, but lower latency, lock. + /// A CPU intensive, but lower latency, lock. /// /// std::atomic_flag seems like it might have been a good option on which /// to base our implementation, but it appears potentially expensive to /// spin over without a cheap read operation. /// - /// satisfies BasicLockable. + /// Satisfies BasicLockable. + /// + /// NOTE: All move operations assume that either the lock is held by the + /// client performing the move, or that is not held by any client. class spinlock { public: spinlock (); @@ -40,5 +42,3 @@ namespace cruft::thread { std::atomic held; }; }; - -#endif