mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 15:53:55 +00:00
1. Fixed compiler warnings
2. Updated thread cleanup/finalizer logic to rely on ctxd if necessary
This commit is contained in:
@@ -969,9 +969,7 @@ duk_ret_t ILibDuktape_GenericMarshal_MethodInvokeAsync_abort(duk_context *ctx)
|
|||||||
// We can gracefully exit this thread
|
// We can gracefully exit this thread
|
||||||
data->abort = 1;
|
data->abort = 1;
|
||||||
sem_post(workAvailable);
|
sem_post(workAvailable);
|
||||||
#ifdef WIN32
|
|
||||||
ILibThread_Join(workerThread);
|
ILibThread_Join(workerThread);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1018,13 +1016,15 @@ duk_ret_t ILibDuktape_GenericMarshal_MethodInvokeAsync_dataFinalizer(duk_context
|
|||||||
void *workerThread = data->workerThread;
|
void *workerThread = data->workerThread;
|
||||||
|
|
||||||
data->abort = 1;
|
data->abort = 1;
|
||||||
sem_post(&(data->workAvailable));
|
sem_post(workAvailable);
|
||||||
#ifdef WIN32
|
|
||||||
ILibThread_Join(workerThread);
|
ILibThread_Join(workerThread);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (duk_ctx_shutting_down(ctx))
|
||||||
|
{
|
||||||
|
ILibLinkedList_AddTail(duk_ctx_context_data(ctx)->threads, data->workerThread);
|
||||||
|
}
|
||||||
data->abort = 1;
|
data->abort = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -653,6 +653,45 @@ void Duktape_SafeDestroyHeap(duk_context *ctx)
|
|||||||
|
|
||||||
ctxd->flags |= duk_destroy_heap_in_progress;
|
ctxd->flags |= duk_destroy_heap_in_progress;
|
||||||
duk_destroy_heap(ctx);
|
duk_destroy_heap(ctx);
|
||||||
|
|
||||||
|
if (ILibLinkedList_GetCount(ctxd->threads) > 0)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
HANDLE* threadList = (HANDLE*)ILibMemory_SmartAllocate(sizeof(HANDLE) * ILibLinkedList_GetCount(ctxd->threads));
|
||||||
|
int i = 0;
|
||||||
|
void *node;
|
||||||
|
while ((node = ILibLinkedList_GetNode_Head(ctxd->threads)) != NULL)
|
||||||
|
{
|
||||||
|
threadList[i++] = ILibLinkedList_GetDataFromNode(node);
|
||||||
|
ILibLinkedList_Remove(node);
|
||||||
|
}
|
||||||
|
WaitForMultipleObjects(i, threadList, TRUE, 5000);
|
||||||
|
ILibMemory_Free(threadList);
|
||||||
|
#else
|
||||||
|
int rv;
|
||||||
|
void *status;
|
||||||
|
long ts = ILibGetTimeStamp(), ts2;
|
||||||
|
struct timespec t;
|
||||||
|
t.tv_sec = 5;
|
||||||
|
t.tv_nsec = 0;
|
||||||
|
|
||||||
|
void *node;
|
||||||
|
while ((node = ILibLinkedList_GetNode_Head(ctxd->threads)) != NULL)
|
||||||
|
{
|
||||||
|
if ((rv = pthread_timedjoin_np((pthread_t)ILibLinkedList_GetDataFromNode(node), &status, &t)) == 0)
|
||||||
|
{
|
||||||
|
t.tv_sec -= (((ts2 = ILibGetTimeStamp()) - ts) / 1000); ts = ts2;
|
||||||
|
if (t.tv_sec == 0) { break; }
|
||||||
|
}
|
||||||
|
else if (rv == ETIMEDOUT)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ILibLinkedList_Remove(node);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
ILibLinkedList_Destroy(ctxd->threads);
|
||||||
ILibMemory_Free(ctxd);
|
ILibMemory_Free(ctxd);
|
||||||
}
|
}
|
||||||
void *Duktape_GetChain(duk_context *ctx)
|
void *Duktape_GetChain(duk_context *ctx)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ typedef struct ILibDuktape_ContextData
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
uint32_t apc_flags;
|
uint32_t apc_flags;
|
||||||
#endif
|
#endif
|
||||||
|
void *threads;
|
||||||
void *chain;
|
void *chain;
|
||||||
void *user;
|
void *user;
|
||||||
}ILibDuktape_ContextData;
|
}ILibDuktape_ContextData;
|
||||||
|
|||||||
@@ -865,7 +865,7 @@ duk_ret_t ILibDuktape_Process_cwd(duk_context *ctx)
|
|||||||
duk_push_string(ctx, ILibScratchPad);
|
duk_push_string(ctx, ILibScratchPad);
|
||||||
return(1);
|
return(1);
|
||||||
#elif defined(_POSIX)
|
#elif defined(_POSIX)
|
||||||
ignore_result((uint64_t)getcwd(ILibScratchPad, sizeof(ILibScratchPad)));
|
ignore_result((uintptr_t)getcwd(ILibScratchPad, sizeof(ILibScratchPad)));
|
||||||
duk_push_string(ctx, ILibScratchPad);
|
duk_push_string(ctx, ILibScratchPad);
|
||||||
return(1);
|
return(1);
|
||||||
#else
|
#else
|
||||||
@@ -1447,7 +1447,6 @@ void *ILibDuktape_ScriptContainer_Engine_realloc(void *udata, void *ptr, duk_siz
|
|||||||
void ILibDuktape_ScriptContainer_Engine_free(void *udata, void *ptr)
|
void ILibDuktape_ScriptContainer_Engine_free(void *udata, void *ptr)
|
||||||
{
|
{
|
||||||
size_t sz = ptr == NULL ? 0 : ILibMemory_Size(ptr);
|
size_t sz = ptr == NULL ? 0 : ILibMemory_Size(ptr);
|
||||||
ILibDuktape_ContextData *x = ptr != NULL ? (ILibDuktape_ContextData*)ILibMemory_Extra(ptr) : NULL;
|
|
||||||
|
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
{
|
{
|
||||||
@@ -2275,6 +2274,7 @@ duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngine_minimal()
|
|||||||
{
|
{
|
||||||
ILibDuktape_ContextData *ctxd = (ILibDuktape_ContextData*)ILibMemory_SmartAllocate(sizeof(ILibDuktape_ContextData));
|
ILibDuktape_ContextData *ctxd = (ILibDuktape_ContextData*)ILibMemory_SmartAllocate(sizeof(ILibDuktape_ContextData));
|
||||||
do { util_random(sizeof(ctxd->nonce), (char*)&(ctxd->nonce)); } while (ctxd->nonce == 0);
|
do { util_random(sizeof(ctxd->nonce), (char*)&(ctxd->nonce)); } while (ctxd->nonce == 0);
|
||||||
|
ctxd->threads = ILibLinkedList_Create();
|
||||||
|
|
||||||
duk_context *ctx = duk_create_heap(ILibDuktape_ScriptContainer_Engine_malloc, ILibDuktape_ScriptContainer_Engine_realloc, ILibDuktape_ScriptContainer_Engine_free, ctxd, ILibDuktape_ScriptContainer_Engine_fatal);
|
duk_context *ctx = duk_create_heap(ILibDuktape_ScriptContainer_Engine_malloc, ILibDuktape_ScriptContainer_Engine_realloc, ILibDuktape_ScriptContainer_Engine_free, ctxd, ILibDuktape_ScriptContainer_Engine_fatal);
|
||||||
if (ctx == NULL) { ILIBCRITICALEXIT(254); }
|
if (ctx == NULL) { ILIBCRITICALEXIT(254); }
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ void ILibDispatchSemaphore_post(sem_t* s);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
static inline void ignore_result(uint64_t result) { (void)result; }
|
static inline void ignore_result(uintptr_t result) { (void)result; }
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
#define PRINTERROR() printf("ERROR in %s, line %d\r\n", __FILE__, __LINE__);
|
#define PRINTERROR() printf("ERROR in %s, line %d\r\n", __FILE__, __LINE__);
|
||||||
|
|||||||
Reference in New Issue
Block a user