]> wimlib.net Git - wimlib/blobdiff - src/lzms-compress.c
lzms-common.c, lzms-compress.c: Use pthread_once()
[wimlib] / src / lzms-compress.c
index 3b0caab4a963e75cd60161d2fb5ddf5a05b8ffe2..2c9356d9b1a538006a7fc9dcae90404bc2c271a2 100644 (file)
@@ -124,7 +124,7 @@ struct lzms_range_encoder {
         * lzms_range_encoder_raw.  */
        struct lzms_range_encoder_raw *rc;
 
-       /* Bits recently encoded by this range encoder.  This are used as in
+       /* Bits recently encoded by this range encoder.  This is used as an
         * index into @prob_entries.  */
        u32 state;
 
@@ -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);
 }
 
 /*