From 3feed7ba074059bf8987470c822b5e1feeef3ee4 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 29 Jan 2020 22:58:59 +1100 Subject: [PATCH] [c-host] make pointer post function thread safe --- c-host/src/app.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/c-host/src/app.c b/c-host/src/app.c index 38ec111a..0ef04c56 100644 --- a/c-host/src/app.c +++ b/c-host/src/app.c @@ -63,6 +63,7 @@ struct app { PLGMPHost lgmp; + LG_Lock pointerPostLock; PLGMPHostQueue pointerQueue; PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN]; PLGMPMemory pointerShape; @@ -300,6 +301,8 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size) void capturePostPointerBuffer(CapturePointer pointer) { + LG_LOCK(app.pointerPostLock); + PLGMPMemory mem; const bool newClient = lgmpHostQueueNewSubs(app.pointerQueue) > 0; @@ -350,6 +353,7 @@ void capturePostPointerBuffer(CapturePointer pointer) default: DEBUG_ERROR("Invalid pointer type"); + LG_UNLOCK(app.pointerPostLock); return; } @@ -359,6 +363,8 @@ void capturePostPointerBuffer(CapturePointer pointer) if ((pointer.shapeUpdate || newClient) && app.pointerShapeValid) flags |= CURSOR_FLAG_SHAPE; + LG_UNLOCK(app.pointerPostLock); + LGMP_STATUS status; while ((status = lgmpHostQueuePost(app.pointerQueue, flags, mem)) != LGMP_OK) { @@ -416,6 +422,8 @@ int app_main(int argc, char * argv[]) return -1; } + LG_LOCK_INIT(app.pointerPostLock); + int exitcode = 0; DEBUG_INFO("IVSHMEM Size : %u MiB", shmDev.size / 1048576); DEBUG_INFO("IVSHMEM Address : 0x%" PRIXPTR, (uintptr_t)shmDev.mem); @@ -554,6 +562,7 @@ fail: lgmpHostFree(&app.lgmp); ivshmemClose(&shmDev); + LG_LOCK_FREE(app.pointerPostLock); return exitcode; }