21 lines
465 B
C++
21 lines
465 B
C++
#ifndef PSCToolbox_SpinLock_H
|
|
#define PSCToolbox_SpinLock_H
|
|
#include <atomic>
|
|
#include <mutex>
|
|
namespace Psc {
|
|
struct Empty_Lock {
|
|
void lock();
|
|
void unlock();
|
|
bool tryLock();
|
|
bool tryLock(int durationMillis);
|
|
};
|
|
struct Spin_Lock {
|
|
void lock();
|
|
bool tryLock();
|
|
bool tryLock(int durationMillis);
|
|
void unlock();
|
|
protected:
|
|
std::atomic_flag flag = ATOMIC_FLAG_INIT;
|
|
};
|
|
}
|
|
#endif |