From b9c9466d6598b36c562bdcf2c964502d5f91fcce Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 15 Dec 2017 16:38:14 +0100 Subject: [PATCH] Handle condition variable failure Add condition variables function wrappers to handle unexpected failure. --- app/src/decoder.c | 2 +- app/src/lockutil.h | 14 ++++++++++++++ app/src/screen.c | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index daba0d07..e9f50645 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -24,7 +24,7 @@ static void push_frame(struct decoder *decoder) { mutex_lock(frames->mutex); if (!decoder->skip_frames) { while (!frames->rendering_frame_consumed) { - SDL_CondWait(frames->rendering_frame_consumed_cond, frames->mutex); + cond_wait(frames->rendering_frame_consumed_cond, frames->mutex); } } else if (!frames->rendering_frame_consumed) { SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "Skip frame"); diff --git a/app/src/lockutil.h b/app/src/lockutil.h index a2e6f0fa..10a9adf2 100644 --- a/app/src/lockutil.h +++ b/app/src/lockutil.h @@ -19,4 +19,18 @@ static inline void mutex_unlock(SDL_mutex *mutex) { } } +static inline void cond_wait(SDL_cond *cond, SDL_mutex *mutex) { + if (SDL_CondWait(cond, mutex)) { + SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not wait on condition"); + exit(1); + } +} + +static inline void cond_signal(SDL_cond *cond) { + if (SDL_CondSignal(cond)) { + SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not signal a condition"); + exit(1); + } +} + #endif diff --git a/app/src/screen.c b/app/src/screen.c index 0dc3265b..b2b49435 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -353,7 +353,7 @@ SDL_bool show_screen(const char *serial, Uint16 local_port) { AVFrame *frame = frames.rendering_frame; frames.rendering_frame_consumed = SDL_TRUE; if (!decoder.skip_frames) { - SDL_CondSignal(frames.rendering_frame_consumed_cond); + cond_signal(frames.rendering_frame_consumed_cond); } struct size current_frame_size = {frame->width, frame->height};