29
29
#include "ruby/util.h"
30
30
#include "ruby_assert.h"
31
31
#include "vm_sync.h"
32
+ #include "ruby_atomic.h"
32
33
33
34
#ifndef ENC_DEBUG
34
35
#define ENC_DEBUG 0
@@ -144,10 +145,14 @@ enc_list_update(int index, rb_raw_encoding *encoding)
144
145
{
145
146
RUBY_ASSERT (index < ENCODING_LIST_CAPA );
146
147
147
- VALUE list = rb_encoding_list ;
148
+ VALUE list = RUBY_ATOMIC_VALUE_LOAD (rb_encoding_list );
149
+
148
150
if (list && NIL_P (rb_ary_entry (list , index ))) {
151
+ VALUE new_list = rb_ary_dup (list );
152
+ RBASIC_CLEAR_CLASS (new_list );
149
153
/* initialize encoding data */
150
- rb_ary_store (list , index , enc_new (encoding ));
154
+ rb_ary_store (new_list , index , enc_new (encoding ));
155
+ RUBY_ATOMIC_VALUE_SET (rb_encoding_list , new_list );
151
156
}
152
157
}
153
158
@@ -157,7 +162,7 @@ enc_list_lookup(int idx)
157
162
VALUE list , enc = Qnil ;
158
163
159
164
if (idx < ENCODING_LIST_CAPA ) {
160
- list = rb_encoding_list ;
165
+ list = RUBY_ATOMIC_VALUE_LOAD ( rb_encoding_list ) ;
161
166
RUBY_ASSERT (list );
162
167
enc = rb_ary_entry (list , idx );
163
168
}
@@ -1387,7 +1392,8 @@ static VALUE
1387
1392
enc_list (VALUE klass )
1388
1393
{
1389
1394
VALUE ary = rb_ary_new2 (0 );
1390
- rb_ary_replace (ary , rb_encoding_list );
1395
+ VALUE list = RUBY_ATOMIC_VALUE_LOAD (rb_encoding_list );
1396
+ rb_ary_replace (ary , list );
1391
1397
return ary ;
1392
1398
}
1393
1399
@@ -1982,9 +1988,9 @@ Init_Encoding(void)
1982
1988
1983
1989
struct enc_table * enc_table = & global_enc_table ;
1984
1990
1991
+ rb_gc_register_address (& rb_encoding_list );
1985
1992
list = rb_encoding_list = rb_ary_new2 (ENCODING_LIST_CAPA );
1986
1993
RBASIC_CLEAR_CLASS (list );
1987
- rb_vm_register_global_object (list );
1988
1994
1989
1995
for (i = 0 ; i < enc_table -> count ; ++ i ) {
1990
1996
rb_ary_push (list , enc_new (enc_table -> list [i ].enc ));
0 commit comments