enderalse/SKSE/Plugins/fs_skse_plugin_functions/common/IInterlockedLong.h
2021-10-06 02:45:46 +02:00

20 lines
591 B
C++

#pragma once
struct IInterlockedLong
{
public:
long Increment(void) { return InterlockedIncrement(&value); }
long Decrement(void) { return InterlockedDecrement(&value); }
long Get(void) { return value; }
long Set(long in) { return InterlockedExchange(&value, in); }
long TrySetIf(long newValue, long expectedOldValue)
{ return InterlockedCompareExchange(&value, newValue, expectedOldValue); }
// interlock variable semantics
bool Claim(void) { return TrySetIf(1, 0) == 0; }
bool Release(void) { return TrySetIf(0, 1) == 1; }
private:
volatile long value;
};