From 539a1235c52a5aa4913e19b282aa3ee8860e4396 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 11 Jul 2020 19:51:15 +0000 Subject: [PATCH] tight2: Fix race --- src/tight-encoder-v2.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tight-encoder-v2.c b/src/tight-encoder-v2.c index a2def23..a264951 100644 --- a/src/tight-encoder-v2.c +++ b/src/tight-encoder-v2.c @@ -405,11 +405,17 @@ static int tight_schedule_zs_work(struct tight_encoder_v2* self, int index) static int tight_schedule_encoding_jobs(struct tight_encoder_v2* self) { + int rc = -1; + + pthread_mutex_lock(&self->wait_mutex); for (int i = 0; i < 4; ++i) if (tight_schedule_zs_work(self, i) < 0) - return -1; + goto failure; - return 0; + rc = 0; +failure: + pthread_mutex_unlock(&self->wait_mutex); + return rc; } static void tight_finish_tile(struct tight_encoder_v2* self,