From 228f5bfdff29685e72dda8d773e5abaef2fd2b6a Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 28 Jan 2020 03:58:28 +1100 Subject: [PATCH] [c-host] don't hog CPU resources if queues are full --- c-host/src/app.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/c-host/src/app.c b/c-host/src/app.c index d13cb03f..a9338cd6 100644 --- a/c-host/src/app.c +++ b/c-host/src/app.c @@ -117,6 +117,13 @@ static int frameThread(void * opaque) while(app.running) { + //wait until there is room in the queue + if(lgmpHostQueuePending(app.frameQueue) == LGMP_Q_FRAME_LEN) + { + usleep(1); + continue; + } + switch(app.iface->waitFrame(&frame)) { case CAPTURE_RESULT_OK: @@ -149,13 +156,6 @@ static int frameThread(void * opaque) } } - //wait until there is room in the queue - if (lgmpHostQueuePending(app.frameQueue) == LGMP_Q_FRAME_LEN) - { - if (!app.running) - break; - } - LGMP_STATUS status; // if we are repeating a frame just send the last frame again @@ -364,7 +364,10 @@ void capturePostPointerBuffer(CapturePointer pointer) while ((status = lgmpHostQueuePost(app.pointerQueue, flags, mem)) != LGMP_OK) { if (status == LGMP_ERR_QUEUE_FULL) + { + usleep(1); continue; + } DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status)); return;