From 4d93b6299c99ca503f378d1e6af29f566fe7e8ab Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 16 Mar 2022 18:51:34 +0900 Subject: [PATCH] Initialize mutex for crypt(3) statically Assuming that all platforms, where only `crypt` is available but not `crypt_r`, are POSIX-base. --- string.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/string.c b/string.c index 7ac11c31d4..a97b6adc67 100644 --- a/string.c +++ b/string.c @@ -10158,35 +10158,12 @@ rb_str_oct(VALUE str) # include "ruby/atomic.h" static struct { - rb_atomic_t initialized; rb_nativethread_lock_t lock; -} crypt_mutex; - -static void -crypt_mutex_destroy(void) -{ - RUBY_ASSERT_ALWAYS(crypt_mutex.initialized == 1); - rb_nativethread_lock_destroy(&crypt_mutex.lock); - crypt_mutex.initialized = 0; -} +} crypt_mutex = {PTHREAD_MUTEX_INITIALIZER}; static void crypt_mutex_initialize(void) { - rb_atomic_t i; - while ((i = RUBY_ATOMIC_CAS(crypt_mutex.initialized, 0, 2)) == 2); - switch (i) { - case 0: - rb_nativethread_lock_initialize(&crypt_mutex.lock); - atexit(crypt_mutex_destroy); - RUBY_ASSERT(crypt_mutex.initialized == 2); - RUBY_ATOMIC_CAS(crypt_mutex.initialized, 2, 1); - break; - case 1: - break; - default: - rb_bug("crypt_mutex.initialized: %d->%d", i, crypt_mutex.initialized); - } } #endif