27 lines
508 B
C++
27 lines
508 B
C++
|
#include "thread/Spinlock.h"
|
||
|
|
||
|
extern "C" void spinlock_lock_acquire(uint64_t* lock);
|
||
|
extern "C" void spinlock_lock_release(uint64_t* lock);
|
||
|
extern "C" int spinlock_lock_is_locked(uint64_t* lock);
|
||
|
|
||
|
void Spinlock::acquire()
|
||
|
{
|
||
|
spinlock_lock_acquire(&m_lock);
|
||
|
}
|
||
|
|
||
|
void Spinlock::release()
|
||
|
{
|
||
|
spinlock_lock_release(&m_lock);
|
||
|
}
|
||
|
|
||
|
bool Spinlock::locked()
|
||
|
{
|
||
|
return spinlock_lock_is_locked(&m_lock);
|
||
|
}
|
||
|
|
||
|
void lock(Spinlock& lock, void (*action)(void))
|
||
|
{
|
||
|
lock.acquire();
|
||
|
action();
|
||
|
lock.release();
|
||
|
}
|