1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-20 18:23:21 +00:00

Fixed spinlocks for ARCHID 7,9,13

This commit is contained in:
Bryan Roe
2020-12-06 00:33:39 -08:00
parent 018ba942a8
commit 462fa965ae
3 changed files with 106 additions and 39 deletions

View File

@@ -116,27 +116,6 @@ struct sockaddr_in6;
#include <sched.h>
#endif
#ifdef WIN32
typedef volatile long ILibSpinLock;
#else
typedef volatile int ILibSpinLock;
#endif
static inline void ILibSpinLock_Init(ILibSpinLock *lock) { *lock = 0; }
static inline void ILibSpinLock_UnLock(ILibSpinLock *lock) { *lock = 0; }
static inline void ILibSpinLock_Lock(ILibSpinLock *lock)
{
#ifdef WIN32
while (!InterlockedCompareExchange(lock, 1, 0))
{
YieldProcessor();
}
#else
while (!__sync_bool_compare_and_swap(lock, 0, 1))
{
sched_yield();
}
#endif
}
#ifdef WIN32
#define ILIB_CURRENT_THREAD (unsigned int)GetCurrentThreadId()
@@ -237,11 +216,6 @@ char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int b
#endif
int ILibGetLocalTime(char *dest, int destLen);
long ILibGetTimeStamp();
@@ -331,6 +305,40 @@ long ILibGetTimeStamp();
#endif
#if defined(ILIBCHAIN_GLOBAL_LOCK)
typedef sem_t* ILibSpinLock;
void ILibSpinLock_Init(ILibSpinLock *lock);
void ILibSpinLock_UnLock(ILibSpinLock *lock);
void ILibSpinLock_Lock(ILibSpinLock *lock);
#else
#ifdef WIN32
typedef volatile long ILibSpinLock;
#else
typedef volatile int ILibSpinLock;
#endif
static inline void ILibSpinLock_Init(ILibSpinLock *lock) { *lock = 0; }
static inline void ILibSpinLock_UnLock(ILibSpinLock *lock) { *lock = 0; }
static inline void ILibSpinLock_Lock(ILibSpinLock *lock)
{
#ifdef WIN32
while (!InterlockedCompareExchange(lock, 1, 0))
{
YieldProcessor();
}
#else
while (!__sync_bool_compare_and_swap(lock, 0, 1))
{
sched_yield();
}
#endif
}
#endif
#if !defined(WIN32)
#define __fastcall