Initialize mutex for crypt(3) statically
Assuming that all platforms, where only `crypt` is available but not `crypt_r`, are POSIX-base.
This commit is contained in:
parent
f91ea23324
commit
4d93b6299c
25
string.c
25
string.c
@ -10158,35 +10158,12 @@ rb_str_oct(VALUE str)
|
|||||||
# include "ruby/atomic.h"
|
# include "ruby/atomic.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
rb_atomic_t initialized;
|
|
||||||
rb_nativethread_lock_t lock;
|
rb_nativethread_lock_t lock;
|
||||||
} crypt_mutex;
|
} crypt_mutex = {PTHREAD_MUTEX_INITIALIZER};
|
||||||
|
|
||||||
static void
|
|
||||||
crypt_mutex_destroy(void)
|
|
||||||
{
|
|
||||||
RUBY_ASSERT_ALWAYS(crypt_mutex.initialized == 1);
|
|
||||||
rb_nativethread_lock_destroy(&crypt_mutex.lock);
|
|
||||||
crypt_mutex.initialized = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
crypt_mutex_initialize(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
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user