From: Eric Biggers Date: Thu, 5 Jun 2014 13:10:18 +0000 (-0500) Subject: lzms-common.c, lzms-compress.c: Use pthread_once() X-Git-Tag: v1.7.0~63 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=ee4fcdd5c4924803ae67a09fecac7d6b4b8ead6e;hp=b9320c921af8d8d2ea3ea80c576ca1e4037af049 lzms-common.c, lzms-compress.c: Use pthread_once() --- 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); } /*