Update release

This commit is contained in:
vczh
2023-04-30 02:21:30 -07:00
parent 878bab1564
commit 422305a3fa
17 changed files with 1407 additions and 1264 deletions
+51
View File
@@ -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.");