From: Stephen Seo Date: Mon, 4 Mar 2019 02:40:34 +0000 (+0900) Subject: Use locks on check_events for threaded case X-Git-Tag: 1.0~237 X-Git-Url: https://git.seodisparate.com/stephenseo/js/darkmode.js?a=commitdiff_plain;h=0f1e9c9aed6af648643134fb24e51625ca1b4fe2;p=UDPConnection Use locks on check_events for threaded case --- diff --git a/src/UDPConnection.c b/src/UDPConnection.c index 34ac079..3448aa2 100644 --- a/src/UDPConnection.c +++ b/src/UDPConnection.c @@ -225,7 +225,11 @@ void UDPC_set_callback_received( void UDPC_check_events(UDPC_Context *ctx) { - // TODO use a lock on receivedPackets + if((ctx->flags & 0x1) != 0) + { + mtx_lock(&ctx->tCVMtx); + } + if(ctx->callbackConnected) { for(int x = 0; x * 4 < ctx->connectedEvents->size; ++x) @@ -278,6 +282,11 @@ void UDPC_check_events(UDPC_Context *ctx) } UDPC_Deque_clear(ctx->receivedPackets); } + + if((ctx->flags & 0x1) != 0) + { + mtx_unlock(&ctx->tCVMtx); + } } int UDPC_queue_send(UDPC_Context *ctx, uint32_t addr, uint32_t isChecked, void *data, uint32_t size)