Fix control stream shutdown

This commit is contained in:
Cameron Gutman 2016-02-15 17:12:27 -05:00
parent 343eeccaa9
commit c18e334cd4

View File

@ -22,6 +22,7 @@ static PLT_THREAD invalidateRefFramesThread;
static PLT_EVENT invalidateRefFramesEvent; static PLT_EVENT invalidateRefFramesEvent;
static int lossCountSinceLastReport; static int lossCountSinceLastReport;
static long currentFrame; static long currentFrame;
static int stopping;
static int idrFrameRequired; static int idrFrameRequired;
static LINKED_BLOCKING_QUEUE invalidReferenceFrameTuples; static LINKED_BLOCKING_QUEUE invalidReferenceFrameTuples;
@ -85,6 +86,7 @@ static char**preconstructedPayloads;
// Initializes the control stream // Initializes the control stream
int initializeControlStream(void) { int initializeControlStream(void) {
stopping = 0;
PltCreateEvent(&invalidateRefFramesEvent); PltCreateEvent(&invalidateRefFramesEvent);
LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20); LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20);
@ -118,6 +120,7 @@ void freeFrameInvalidationList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
// Cleans up control stream // Cleans up control stream
void destroyControlStream(void) { void destroyControlStream(void) {
LC_ASSERT(stopping);
PltCloseEvent(&invalidateRefFramesEvent); PltCloseEvent(&invalidateRefFramesEvent);
freeFrameInvalidationList(LbqDestroyLinkedBlockingQueue(&invalidReferenceFrameTuples)); freeFrameInvalidationList(LbqDestroyLinkedBlockingQueue(&invalidReferenceFrameTuples));
} }
@ -359,6 +362,11 @@ static void invalidateRefFramesFunc(void* context) {
PltWaitForEvent(&invalidateRefFramesEvent); PltWaitForEvent(&invalidateRefFramesEvent);
PltClearEvent(&invalidateRefFramesEvent); PltClearEvent(&invalidateRefFramesEvent);
// Bail if we've been shutdown
if (stopping) {
break;
}
// Sometimes we absolutely need an IDR frame // Sometimes we absolutely need an IDR frame
if (idrFrameRequired) { if (idrFrameRequired) {
// Empty invalidate reference frames tuples // Empty invalidate reference frames tuples
@ -380,6 +388,10 @@ static void invalidateRefFramesFunc(void* context) {
// Stops the control stream // Stops the control stream
int stopControlStream(void) { int stopControlStream(void) {
stopping = 1;
LbqSignalQueueShutdown(&invalidReferenceFrameTuples);
PltSetEvent(&invalidateRefFramesEvent);
PltInterruptThread(&lossStatsThread); PltInterruptThread(&lossStatsThread);
PltInterruptThread(&invalidateRefFramesThread); PltInterruptThread(&invalidateRefFramesThread);