2018-03-14 16:39:10 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/.
|
2018-03-14 16:39:10 +11:00
|
|
|
*
|
|
|
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ticketlock.hpp"
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using cruft::thread::ticketlock;
|
2018-03-14 16:39:10 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
ticketlock::ticketlock ():
|
|
|
|
current (0),
|
|
|
|
next (0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
ticketlock::lock (void)
|
|
|
|
{
|
|
|
|
auto self = next++;
|
|
|
|
|
|
|
|
while (current != self)
|
|
|
|
__asm__ volatile ("pause");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
ticketlock::unlock (void)
|
|
|
|
{
|
|
|
|
++current;
|
|
|
|
}
|