diff --git a/class.c b/class.c index c31d1a9be7..142d0411a4 100644 --- a/class.c +++ b/class.c @@ -446,8 +446,7 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module) entry = ZALLOC(rb_subclass_entry_t); entry->klass = klass; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { anchor = RCLASS_WRITABLE_SUBCLASSES(super); VM_ASSERT(anchor); ns_subclasses = (rb_ns_subclasses_t *)anchor->ns_subclasses; @@ -464,7 +463,6 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module) entry->prev = head; st_insert(tbl, namespace_subclasses_tbl_key(ns), (st_data_t)entry); } - RB_VM_LOCK_LEAVE(); if (is_module) { RCLASS_WRITE_NS_MODULE_SUBCLASSES(klass, anchor->ns_subclasses); diff --git a/gc.c b/gc.c index aba799ab25..2ce39004eb 100644 --- a/gc.c +++ b/gc.c @@ -2280,11 +2280,9 @@ classext_fields_hash_memsize(rb_classext_t *ext, bool prime, VALUE namespace, vo { size_t *size = (size_t *)arg; size_t count; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { count = rb_st_table_size((st_table *)RCLASSEXT_FIELDS(ext)); } - RB_VM_LOCK_LEAVE(); // class IV sizes are allocated as powers of two *size += SIZEOF_VALUE << bit_length(count); } @@ -4570,8 +4568,7 @@ ruby_gc_set_params(void) void rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *data) { - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { if (rb_gc_impl_during_gc_p(rb_gc_get_objspace())) rb_bug("rb_objspace_reachable_objects_from() is not supported while during GC"); if (!RB_SPECIAL_CONST_P(obj)) { @@ -4587,7 +4584,6 @@ rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void * vm->gc.mark_func_data = prev_mfd; } } - RB_VM_LOCK_LEAVE(); } struct root_objects_data { diff --git a/hash.c b/hash.c index 608738aab5..2cc6828bb0 100644 --- a/hash.c +++ b/hash.c @@ -5170,8 +5170,7 @@ extern char **environ; #define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0) #endif -#define ENV_LOCK() RB_VM_LOCK_ENTER() -#define ENV_UNLOCK() RB_VM_LOCK_LEAVE() +#define ENV_LOCKING() RB_VM_LOCKING() static inline rb_encoding * env_encoding(void) @@ -5209,12 +5208,10 @@ static VALUE getenv_with_lock(const char *name) { VALUE ret; - ENV_LOCK(); - { + ENV_LOCKING() { const char *val = getenv(name); ret = env_str_new2(val); } - ENV_UNLOCK(); return ret; } @@ -5223,11 +5220,9 @@ has_env_with_lock(const char *name) { const char *val; - ENV_LOCK(); - { + ENV_LOCKING() { val = getenv(name); } - ENV_UNLOCK(); return val ? true : false; } @@ -5477,13 +5472,11 @@ ruby_setenv(const char *name, const char *value) *wvalue = L'\0'; } - ENV_LOCK(); - { + ENV_LOCKING() { /* Use _wputenv_s() instead of SetEnvironmentVariableW() to make sure * special variables like "TZ" are interpret by libc. */ failed = _wputenv_s(wname, wvalue); } - ENV_UNLOCK(); ALLOCV_END(buf); /* even if putenv() failed, clean up and try to delete the @@ -5500,28 +5493,22 @@ ruby_setenv(const char *name, const char *value) #elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV) if (value) { int ret; - ENV_LOCK(); - { + ENV_LOCKING() { ret = setenv(name, value, 1); } - ENV_UNLOCK(); if (ret) rb_sys_fail_sprintf("setenv(%s)", name); } else { #ifdef VOID_UNSETENV - ENV_LOCK(); - { + ENV_LOCKING() { unsetenv(name); } - ENV_UNLOCK(); #else int ret; - ENV_LOCK(); - { + ENV_LOCKING() { ret = unsetenv(name); } - ENV_UNLOCK(); if (ret) rb_sys_fail_sprintf("unsetenv(%s)", name); #endif @@ -5544,8 +5531,7 @@ ruby_setenv(const char *name, const char *value) snprintf(mem_ptr, mem_size, "%s=%s", name, value); } - ENV_LOCK(); - { + ENV_LOCKING() { for (env_ptr = GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) { if (!strncmp(str, name, len) && str[len] == '=') { if (!in_origenv(str)) free(str); @@ -5554,15 +5540,12 @@ ruby_setenv(const char *name, const char *value) } } } - ENV_UNLOCK(); if (value) { int ret; - ENV_LOCK(); - { + ENV_LOCKING() { ret = putenv(mem_ptr); } - ENV_UNLOCK(); if (ret) { free(mem_ptr); @@ -5573,8 +5556,7 @@ ruby_setenv(const char *name, const char *value) size_t len; int i; - ENV_LOCK(); - { + ENV_LOCKING() { i = envix(name); /* where does it go? */ if (environ == origenviron) { /* need we copy environment? */ @@ -5615,7 +5597,6 @@ ruby_setenv(const char *name, const char *value) finish:; } - ENV_UNLOCK(); #endif /* WIN32 */ } @@ -5700,8 +5681,7 @@ env_keys(int raw) rb_encoding *enc = raw ? 0 : rb_locale_encoding(); VALUE ary = rb_ary_new(); - ENV_LOCK(); - { + ENV_LOCKING() { char **env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); @@ -5715,7 +5695,6 @@ env_keys(int raw) } FREE_ENVIRON(environ); } - ENV_UNLOCK(); return ary; } @@ -5745,8 +5724,7 @@ rb_env_size(VALUE ehash, VALUE args, VALUE eobj) char **env; long cnt = 0; - ENV_LOCK(); - { + ENV_LOCKING() { env = GET_ENVIRON(environ); for (; *env ; ++env) { if (strchr(*env, '=')) { @@ -5755,7 +5733,6 @@ rb_env_size(VALUE ehash, VALUE args, VALUE eobj) } FREE_ENVIRON(environ); } - ENV_UNLOCK(); return LONG2FIX(cnt); } @@ -5796,8 +5773,7 @@ env_values(void) { VALUE ary = rb_ary_new(); - ENV_LOCK(); - { + ENV_LOCKING() { char **env = GET_ENVIRON(environ); while (*env) { @@ -5809,7 +5785,6 @@ env_values(void) } FREE_ENVIRON(environ); } - ENV_UNLOCK(); return ary; } @@ -5890,8 +5865,7 @@ env_each_pair(VALUE ehash) VALUE ary = rb_ary_new(); - ENV_LOCK(); - { + ENV_LOCKING() { char **env = GET_ENVIRON(environ); while (*env) { @@ -5904,7 +5878,6 @@ env_each_pair(VALUE ehash) } FREE_ENVIRON(environ); } - ENV_UNLOCK(); if (rb_block_pair_yield_optimizable()) { for (i=0; i