thread/spinlock: assert the lock isn't held at destruction

This commit is contained in:
Danny Robson 2019-05-24 12:05:38 +10:00
parent 747cfa9237
commit 2153feafc1
2 changed files with 15 additions and 1 deletions

View File

@ -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;
}

View File

@ -24,6 +24,8 @@ namespace cruft::thread {
class spinlock {
public:
spinlock ();
~spinlock ();
spinlock (spinlock &&) noexcept;
spinlock& operator= (spinlock &&) noexcept;