1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-19 17:53:28 +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

@@ -220,7 +220,7 @@ ifeq ($(ARCHID),7)
ARCHNAME = mips ARCHNAME = mips
CC = $(PATH_MIPS)mipsel-linux-gcc CC = $(PATH_MIPS)mipsel-linux-gcc
STRIP = $(PATH_MIPS)mipsel-linux-strip STRIP = $(PATH_MIPS)mipsel-linux-strip
CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing -DILIBCHAIN_GLOBAL_LOCK
CFLAGS += -DBADMATH CFLAGS += -DBADMATH
IPADDR_MONITOR_DISABLE = 1 IPADDR_MONITOR_DISABLE = 1
IFADDR_DISABLE = 1 IFADDR_DISABLE = 1
@@ -251,6 +251,7 @@ STRIP = $(PATH_ARM5)arm-none-linux-gnueabi-strip
KVM = 0 KVM = 0
LMS = 0 LMS = 0
CFLAGS += -D_NOFSWATCHER CFLAGS += -D_NOFSWATCHER
CFLAGS += -DILIBCHAIN_GLOBAL_LOCK
CEXTRA = -fno-strict-aliasing CEXTRA = -fno-strict-aliasing
endif endif
@@ -261,7 +262,7 @@ CC = $(PATH_POGO)arm-none-linux-gnueabi-gcc
STRIP = $(PATH_POGO)arm-none-linux-gnueabi-strip STRIP = $(PATH_POGO)arm-none-linux-gnueabi-strip
KVM = 0 KVM = 0
LMS = 0 LMS = 0
CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing -DILIBCHAIN_GLOBAL_LOCK
endif endif
# Official Linux POKY # Official Linux POKY

View File

@@ -1928,12 +1928,17 @@ void *ILibCreateChainEx(int extraMemorySize)
{ {
struct ILibBaseChain *RetVal; struct ILibBaseChain *RetVal;
if (ILibChainLock_RefCounter == 0)
{
sem_init(&ILibChainLock, 0, 1);
}
ILibChainLock_RefCounter++;
#if defined(WIN32) || defined(_WIN32_WCE) #if defined(WIN32) || defined(_WIN32_WCE)
WORD wVersionRequested; WORD wVersionRequested;
WSADATA wsaData; WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 0); wVersionRequested = MAKEWORD(2, 0);
if (WSAStartup(wVersionRequested, &wsaData) != 0) { ILIBCRITICALEXIT(1); } if (WSAStartup(wVersionRequested, &wsaData) != 0) { ILIBCRITICALEXIT(1); }
#endif #endif
RetVal = ILibMemory_Allocate(sizeof(ILibBaseChain), extraMemorySize, NULL, NULL); RetVal = ILibMemory_Allocate(sizeof(ILibBaseChain), extraMemorySize, NULL, NULL);
@@ -1948,12 +1953,6 @@ void *ILibCreateChainEx(int extraMemorySize)
#endif #endif
RetVal->TerminateFlag = 0; RetVal->TerminateFlag = 0;
if (ILibChainLock_RefCounter == 0)
{
sem_init(&ILibChainLock, 0, 1);
}
ILibChainLock_RefCounter++;
RetVal->Timer = ILibCreateLifeTime(RetVal); RetVal->Timer = ILibCreateLifeTime(RetVal);
#if defined(WIN32) #if defined(WIN32)
@@ -2408,7 +2407,7 @@ ILibExportMethod void ILibChain_Continue(void *Chain, ILibChain_Link **modules,
// //
FD_SET(root->TerminatePipe[0], &readset); FD_SET(root->TerminatePipe[0], &readset);
#endif #endif
sem_wait(&ILibChainLock);
while (ILibLinkedList_GetCount(((ILibBaseChain*)Chain)->LinksPendingDelete) > 0) while (ILibLinkedList_GetCount(((ILibBaseChain*)Chain)->LinksPendingDelete) > 0)
{ {
chain->node = ILibLinkedList_GetNode_Head(((ILibBaseChain*)Chain)->LinksPendingDelete); chain->node = ILibLinkedList_GetNode_Head(((ILibBaseChain*)Chain)->LinksPendingDelete);
@@ -2422,7 +2421,6 @@ ILibExportMethod void ILibChain_Continue(void *Chain, ILibChain_Link **modules,
ILibChain_FreeLink(module); ILibChain_FreeLink(module);
} }
} }
sem_post(&ILibChainLock);
// //
// The actual Select Statement // The actual Select Statement
@@ -3763,7 +3761,7 @@ ILibExportMethod void ILibStartChain(void *Chain)
// //
FD_SET(chain->TerminatePipe[0], &readset); FD_SET(chain->TerminatePipe[0], &readset);
#endif #endif
sem_wait(&ILibChainLock);
while (ILibLinkedList_GetCount(((ILibBaseChain*)Chain)->LinksPendingDelete) > 0) while (ILibLinkedList_GetCount(((ILibBaseChain*)Chain)->LinksPendingDelete) > 0)
{ {
chain->node = ILibLinkedList_GetNode_Head(((ILibBaseChain*)Chain)->LinksPendingDelete); chain->node = ILibLinkedList_GetNode_Head(((ILibBaseChain*)Chain)->LinksPendingDelete);
@@ -3777,7 +3775,6 @@ ILibExportMethod void ILibStartChain(void *Chain)
ILibChain_FreeLink(module); ILibChain_FreeLink(module);
} }
} }
sem_post(&ILibChainLock);
// //
// The actual Select Statement // The actual Select Statement
@@ -10842,3 +10839,64 @@ int ILibLinkedList_FileBacked_AddTail(ILibLinkedList_FileBacked_Root* root, char
fflush(source); fflush(source);
return 0; return 0;
} }
#if defined(ILIBCHAIN_GLOBAL_LOCK)
int g_ILibSpinLock_acquired = 0;
#ifdef WIN32
DWORD g_ILibSpinLock_acquired_threadid;
#else
pthread_t g_ILibSpinLock_acquired_threadid;
#endif
void ILibSpinLock_Init(ILibSpinLock *lock)
{
if (ILibChainLock_RefCounter == 0)
{
++ILibChainLock_RefCounter;
sem_init(&ILibChainLock, 0, 1);
}
*lock = &ILibChainLock;
}
void ILibSpinLock_UnLock(ILibSpinLock *lock)
{
sem_wait(*lock);
g_ILibSpinLock_acquired = 0;
sem_post(*lock);
}
void ILibSpinLock_Lock(ILibSpinLock *lock)
{
int i = 1;
while (i != 0)
{
sem_wait(*lock);
if (g_ILibSpinLock_acquired == 0)
{
g_ILibSpinLock_acquired = 1;
#ifdef WIN32
g_ILibSpinLock_acquired_threadid = GetCurrentThreadId();
#else
g_ILibSpinLock_acquired_threadid = pthread_self();
#endif
i = 0;
}
else
{
#ifdef WIN32
if (g_ILibSpinLock_acquired_threadid == GetCurrentThreadId()) { i = 0; }
#else
if (pthread_equal(g_ILibSpinLock_acquired_threadid, pthread_self())) { i = 0; }
#endif
}
sem_post(*lock);
if (i != 0)
{
#ifdef WIN32
YieldProcessor();
#else
sched_yield();
#endif
}
}
}
#endif

View File

@@ -116,27 +116,6 @@ struct sockaddr_in6;
#include <sched.h> #include <sched.h>
#endif #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 #ifdef WIN32
#define ILIB_CURRENT_THREAD (unsigned int)GetCurrentThreadId() #define ILIB_CURRENT_THREAD (unsigned int)GetCurrentThreadId()
@@ -237,11 +216,6 @@ char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int b
#endif #endif
int ILibGetLocalTime(char *dest, int destLen); int ILibGetLocalTime(char *dest, int destLen);
long ILibGetTimeStamp(); long ILibGetTimeStamp();
@@ -331,6 +305,40 @@ long ILibGetTimeStamp();
#endif #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) #if !defined(WIN32)
#define __fastcall #define __fastcall