thread/spinlock: don't try to lock during a move operation
This commit is contained in:
parent
ec883c3009
commit
747cfa9237
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <danny@nerdcruft.net>
|
||||
* Copyright 2018-2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_THREAD_SPINLOCK_HPP
|
||||
#define CRUFT_UTIL_THREAD_SPINLOCK_HPP
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
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<bool> held;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user