mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-05-25 00:53:18 +08:00
Update release
This commit is contained in:
@@ -460,8 +460,59 @@ Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#if defined VCZH_ARM
|
||||
#elif defined VCZH_MSVC || defined VCZH_GCC
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
|
||||
/***********************************************************************
|
||||
SpinLock
|
||||
***********************************************************************/
|
||||
|
||||
SpinLock::Scope::Scope(SpinLock& _spinLock)
|
||||
:spinLock(&_spinLock)
|
||||
{
|
||||
spinLock->Enter();
|
||||
}
|
||||
|
||||
SpinLock::Scope::~Scope()
|
||||
{
|
||||
spinLock->Leave();
|
||||
}
|
||||
|
||||
bool SpinLock::TryEnter()
|
||||
{
|
||||
return token.exchange(1) == 0;
|
||||
}
|
||||
|
||||
void SpinLock::Enter()
|
||||
{
|
||||
vint expected = 0;
|
||||
while (!token.compare_exchange_strong(expected, 1))
|
||||
{
|
||||
while (token != 0)
|
||||
{
|
||||
#ifdef VCZH_ARM
|
||||
__yield();
|
||||
#else
|
||||
_mm_pause();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpinLock::Leave()
|
||||
{
|
||||
token.exchange(0);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
ThreadLocalStorage
|
||||
***********************************************************************/
|
||||
|
||||
void ThreadLocalStorage::Clear()
|
||||
{
|
||||
CHECK_ERROR(!disposed, L"vl::ThreadLocalStorage::Clear()#Cannot access a disposed ThreadLocalStorage.");
|
||||
|
||||
Reference in New Issue
Block a user