mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/etc] Make Ractor safe
This commit is contained in:
parent
3286380ebc
commit
cd63f0358f
Notes:
git
2020-12-23 09:46:32 +09:00
3 changed files with 46 additions and 14 deletions
|
@ -6,6 +6,20 @@ constdefs.h : $(srcdir)/mkconstants.rb
|
||||||
etc.o: $(RUBY_EXTCONF_H)
|
etc.o: $(RUBY_EXTCONF_H)
|
||||||
etc.o: $(arch_hdrdir)/ruby/config.h
|
etc.o: $(arch_hdrdir)/ruby/config.h
|
||||||
etc.o: $(hdrdir)/ruby.h
|
etc.o: $(hdrdir)/ruby.h
|
||||||
|
etc.o: $(hdrdir)/ruby/assert.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/assume.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/attributes.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/bool.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/gcc_version_since.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/limits.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/long_long.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/stdalign.h
|
||||||
|
etc.o: $(hdrdir)/ruby/backward/2/stdarg.h
|
||||||
|
etc.o: $(hdrdir)/ruby/defines.h
|
||||||
|
etc.o: $(hdrdir)/ruby/encoding.h
|
||||||
|
etc.o: $(hdrdir)/ruby/intern.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/anyargs.h
|
etc.o: $(hdrdir)/ruby/internal/anyargs.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/arithmetic.h
|
etc.o: $(hdrdir)/ruby/internal/arithmetic.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/arithmetic/char.h
|
etc.o: $(hdrdir)/ruby/internal/arithmetic/char.h
|
||||||
|
@ -146,20 +160,6 @@ etc.o: $(hdrdir)/ruby/internal/value_type.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/variable.h
|
etc.o: $(hdrdir)/ruby/internal/variable.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/warning_push.h
|
etc.o: $(hdrdir)/ruby/internal/warning_push.h
|
||||||
etc.o: $(hdrdir)/ruby/internal/xmalloc.h
|
etc.o: $(hdrdir)/ruby/internal/xmalloc.h
|
||||||
etc.o: $(hdrdir)/ruby/assert.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/assume.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/attributes.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/bool.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/gcc_version_since.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/limits.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/long_long.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/stdalign.h
|
|
||||||
etc.o: $(hdrdir)/ruby/backward/2/stdarg.h
|
|
||||||
etc.o: $(hdrdir)/ruby/defines.h
|
|
||||||
etc.o: $(hdrdir)/ruby/encoding.h
|
|
||||||
etc.o: $(hdrdir)/ruby/intern.h
|
|
||||||
etc.o: $(hdrdir)/ruby/io.h
|
etc.o: $(hdrdir)/ruby/io.h
|
||||||
etc.o: $(hdrdir)/ruby/missing.h
|
etc.o: $(hdrdir)/ruby/missing.h
|
||||||
etc.o: $(hdrdir)/ruby/onigmo.h
|
etc.o: $(hdrdir)/ruby/onigmo.h
|
||||||
|
@ -167,6 +167,7 @@ etc.o: $(hdrdir)/ruby/oniguruma.h
|
||||||
etc.o: $(hdrdir)/ruby/ruby.h
|
etc.o: $(hdrdir)/ruby/ruby.h
|
||||||
etc.o: $(hdrdir)/ruby/st.h
|
etc.o: $(hdrdir)/ruby/st.h
|
||||||
etc.o: $(hdrdir)/ruby/subst.h
|
etc.o: $(hdrdir)/ruby/subst.h
|
||||||
|
etc.o: $(hdrdir)/ruby/thread_native.h
|
||||||
etc.o: constdefs.h
|
etc.o: constdefs.h
|
||||||
etc.o: etc.c
|
etc.o: etc.c
|
||||||
# AUTOGENERATED DEPENDENCIES END
|
# AUTOGENERATED DEPENDENCIES END
|
||||||
|
|
|
@ -62,6 +62,10 @@ void rb_deprecate_constant(VALUE mod, const char *name);
|
||||||
|
|
||||||
#include "constdefs.h"
|
#include "constdefs.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
||||||
|
#include "ruby/thread_native.h"
|
||||||
|
#else
|
||||||
|
/* Implement rb_native_mutex_x using an int */
|
||||||
typedef int rb_nativethread_lock_t;
|
typedef int rb_nativethread_lock_t;
|
||||||
static int rb_native_mutex_trylock(int *mutex) {
|
static int rb_native_mutex_trylock(int *mutex) {
|
||||||
if (*mutex) {
|
if (*mutex) {
|
||||||
|
@ -74,6 +78,7 @@ static void rb_native_mutex_unlock(int *mutex) {
|
||||||
*mutex = 0;
|
*mutex = 0;
|
||||||
}
|
}
|
||||||
#define rb_native_mutex_initialize rb_native_mutex_unlock
|
#define rb_native_mutex_initialize rb_native_mutex_unlock
|
||||||
|
#endif
|
||||||
|
|
||||||
/* call-seq:
|
/* call-seq:
|
||||||
* getlogin -> String
|
* getlogin -> String
|
||||||
|
@ -1087,6 +1092,9 @@ Init_etc(void)
|
||||||
{
|
{
|
||||||
VALUE mEtc;
|
VALUE mEtc;
|
||||||
|
|
||||||
|
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
||||||
|
RB_EXT_RACTOR_SAFE(true);
|
||||||
|
#endif
|
||||||
mEtc = rb_define_module("Etc");
|
mEtc = rb_define_module("Etc");
|
||||||
rb_define_const(mEtc, "VERSION", rb_str_new_cstr(RUBY_ETC_VERSION));
|
rb_define_const(mEtc, "VERSION", rb_str_new_cstr(RUBY_ETC_VERSION));
|
||||||
init_constants(mEtc);
|
init_constants(mEtc);
|
||||||
|
|
|
@ -169,4 +169,27 @@ class TestEtc < Test::Unit::TestCase
|
||||||
assert_operator(1, :<=, n)
|
assert_operator(1, :<=, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ractor
|
||||||
|
return unless Etc.passwd # => skip test if no platform support
|
||||||
|
|
||||||
|
assert_ractor(<<~RUBY, require: 'etc')
|
||||||
|
ractor = Ractor.new do
|
||||||
|
Etc.passwd do |s|
|
||||||
|
Ractor.yield :sync
|
||||||
|
Ractor.yield s.name
|
||||||
|
break :done
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ractor.take # => :sync
|
||||||
|
assert_raise RuntimeError, /parallel/ do
|
||||||
|
Etc.passwd {}
|
||||||
|
end
|
||||||
|
name = ractor.take # => first name
|
||||||
|
ractor.take # => :done
|
||||||
|
name2 = Etc.passwd do |s|
|
||||||
|
break s.name
|
||||||
|
end
|
||||||
|
assert_equal(name2, name)
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue