int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) { PLINKED_BLOCKING_QUEUE_ENTRY entry; int err; for (;;) { err = PltWaitForEvent(&queueHead->containsDataEvent); if (err != PLT_WAIT_SUCCESS) { return LBQ_INTERRUPTED; } PltLockMutex(&queueHead->mutex); if (queueHead->head == NULL) { PltClearEvent(&queueHead->containsDataEvent); PltUnlockMutex(&queueHead->mutex); continue; } entry = queueHead->head; queueHead->head = entry->flink; queueHead->currentSize--; if (queueHead->head == NULL) { LC_ASSERT(queueHead->currentSize == 0); queueHead->tail = NULL; PltClearEvent(&queueHead->containsDataEvent); } else { LC_ASSERT(queueHead->currentSize != 0); queueHead->head->blink = NULL; } *data = entry->data; PltUnlockMutex(&queueHead->mutex); break; } return LBQ_SUCCESS; }
static void invalidateRefFramesFunc(void* context) { while (!PltIsThreadInterrupted(&invalidateRefFramesThread)) { // Wait for a request to invalidate reference frames PltWaitForEvent(&invalidateRefFramesEvent); PltClearEvent(&invalidateRefFramesEvent); // Sometimes we absolutely need an IDR frame if (idrFrameRequired) { // Empty invalidate reference frames tuples PQUEUED_FRAME_INVALIDATION_TUPLE qfit; while (getNextFrameInvalidationTuple(&qfit)) { free(qfit); } // Send an IDR frame request idrFrameRequired = 0; requestIdrFrame(); } else { // Otherwise invalidate reference frames requestInvalidateReferenceFrames(); } } }
static void resyncThreadFunc(void* context) { long long payload[3]; while (!PltIsThreadInterrupted(&resyncThread)) { // Wait for a resync request PltWaitForEvent(&resyncEvent); // Form the payload payload[0] = 0; payload[1] = 0xFFFFF; payload[2] = 0; // Done capturing the parameters PltClearEvent(&resyncEvent); // Send the resync request and read the response if (!sendMessageAndDiscardReply(packetTypes[IDX_RESYNC], payloadLengths[IDX_RESYNC], payload)) { Limelog("Resync: Transaction failed: %d\n", (int)LastSocketError()); ListenerCallbacks.connectionTerminated(LastSocketError()); return; } Limelog("Resync complete\n"); } }