From ee4fcdd5c4924803ae67a09fecac7d6b4b8ead6e Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 5 Jun 2014 08:10:18 -0500 Subject: [PATCH] lzms-common.c, lzms-compress.c: Use pthread_once() --- src/lzms-common.c | 14 +++----------- src/lzms-compress.c | 14 +++----------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/lzms-common.c b/src/lzms-common.c index a34fb245..c657ef4a 100644 --- a/src/lzms-common.c +++ b/src/lzms-common.c @@ -165,17 +165,9 @@ lzms_compute_slots(void) void lzms_init_slots(void) { - static bool done = false; - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - - if (unlikely(!done)) { - pthread_mutex_lock(&mutex); - if (!done) { - lzms_compute_slots(); - done = true; - } - pthread_mutex_unlock(&mutex); - } + static pthread_once_t once = PTHREAD_ONCE_INIT; + + pthread_once(&once, lzms_compute_slots); } static s32 diff --git a/src/lzms-compress.c b/src/lzms-compress.c index 763be005..2c9356d9 100644 --- a/src/lzms-compress.c +++ b/src/lzms-compress.c @@ -666,17 +666,9 @@ lzms_do_init_rc_costs(void) static void lzms_init_rc_costs(void) { - static bool done = false; - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - - if (unlikely(!done)) { - pthread_mutex_lock(&mutex); - if (!done) { - lzms_do_init_rc_costs(); - done = true; - } - pthread_mutex_unlock(&mutex); - } + static pthread_once_t once = PTHREAD_ONCE_INIT; + + pthread_once(&once, lzms_do_init_rc_costs); } /* -- 2.43.0