1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

sync fstring pool

fstring pool should be sync with other Ractors.
This commit is contained in:
Koichi Sasada 2020-09-11 18:31:15 +09:00
parent 74ddac1c82
commit e81d7189a0
Notes: git 2020-09-15 00:05:41 +09:00
3 changed files with 32 additions and 6 deletions

View file

@ -521,4 +521,21 @@ assert_equal 'nil', %q{
r.name.inspect
}
###
### Synchronization tests
###
N = 100_000
# fstring pool
assert_equal "#{N}#{N}", %Q{
N = #{N}
2.times.map{
Ractor.new{
N.times{|i| -(i.to_s)}
}
}.map{|r| r.take}.join
}
end # if !ENV['GITHUB_WORKFLOW']

View file

@ -13351,6 +13351,7 @@ string.$(OBJEXT): {$(VPATH)}internal/variable.h
string.$(OBJEXT): {$(VPATH)}internal/warning_push.h
string.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
string.$(OBJEXT): {$(VPATH)}missing.h
string.$(OBJEXT): {$(VPATH)}node.h
string.$(OBJEXT): {$(VPATH)}onigmo.h
string.$(OBJEXT): {$(VPATH)}oniguruma.h
string.$(OBJEXT): {$(VPATH)}probes.dmyh
@ -13362,6 +13363,8 @@ string.$(OBJEXT): {$(VPATH)}st.h
string.$(OBJEXT): {$(VPATH)}string.c
string.$(OBJEXT): {$(VPATH)}subst.h
string.$(OBJEXT): {$(VPATH)}util.h
string.$(OBJEXT): {$(VPATH)}vm_debug.h
string.$(OBJEXT): {$(VPATH)}vm_sync.h
strlcat.$(OBJEXT): {$(VPATH)}config.h
strlcat.$(OBJEXT): {$(VPATH)}internal/compiler_is.h
strlcat.$(OBJEXT): {$(VPATH)}internal/compiler_is/apple.h

View file

@ -53,6 +53,7 @@
#include "ruby/re.h"
#include "ruby/util.h"
#include "ruby_assert.h"
#include "vm_sync.h"
#define BEG(no) (regs->beg[(no)])
#define END(no) (regs->end[(no)])
@ -364,13 +365,18 @@ static VALUE
register_fstring(VALUE str)
{
VALUE ret;
st_table *frozen_strings = rb_vm_fstring_table();
do {
ret = str;
st_update(frozen_strings, (st_data_t)str,
fstr_update_callback, (st_data_t)&ret);
} while (ret == Qundef);
RB_VM_LOCK_ENTER();
{
st_table *frozen_strings = rb_vm_fstring_table();
do {
ret = str;
st_update(frozen_strings, (st_data_t)str,
fstr_update_callback, (st_data_t)&ret);
} while (ret == Qundef);
}
RB_VM_LOCK_LEAVE();
assert(OBJ_FROZEN(ret));
assert(!FL_TEST_RAW(ret, STR_FAKESTR));