From 2153feafc118307c21ffa9c54aa705aa39a94c51 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 24 May 2019 12:05:38 +1000 Subject: [PATCH] thread/spinlock: assert the lock isn't held at destruction --- thread/spinlock.cpp | 14 +++++++++++++- thread/spinlock.hpp | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/thread/spinlock.cpp b/thread/spinlock.cpp index 93cd176d..4d4c5652 100644 --- a/thread/spinlock.cpp +++ b/thread/spinlock.cpp @@ -21,16 +21,28 @@ spinlock::spinlock (): { ; } +//----------------------------------------------------------------------------- +spinlock::~spinlock () +{ + CHECK (!held); +} + + //----------------------------------------------------------------------------- spinlock::spinlock (spinlock &&rhs) noexcept: held (rhs.held.load ()) -{ ; } +{ + rhs.held = false; +} //----------------------------------------------------------------------------- spinlock& spinlock::operator= (spinlock &&rhs) noexcept { + CHECK (!held); + held = rhs.held.load (); + rhs.held = false; return *this; } diff --git a/thread/spinlock.hpp b/thread/spinlock.hpp index 2d6a14e5..958eb6d8 100644 --- a/thread/spinlock.hpp +++ b/thread/spinlock.hpp @@ -24,6 +24,8 @@ namespace cruft::thread { class spinlock { public: spinlock (); + ~spinlock (); + spinlock (spinlock &&) noexcept; spinlock& operator= (spinlock &&) noexcept;