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

fix public interface

To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
This commit is contained in:
Koichi Sasada 2020-11-17 16:40:47 +09:00
parent 0683912db8
commit 5e3259ea74
Notes: git 2020-11-18 03:53:22 +09:00
23 changed files with 121 additions and 135 deletions

View file

@ -3372,7 +3372,7 @@ cont.$(OBJEXT): {$(VPATH)}missing.h
cont.$(OBJEXT): {$(VPATH)}mjit.h cont.$(OBJEXT): {$(VPATH)}mjit.h
cont.$(OBJEXT): {$(VPATH)}node.h cont.$(OBJEXT): {$(VPATH)}node.h
cont.$(OBJEXT): {$(VPATH)}ractor.h cont.$(OBJEXT): {$(VPATH)}ractor.h
cont.$(OBJEXT): {$(VPATH)}ractor_pub.h cont.$(OBJEXT): {$(VPATH)}ractor_core.h
cont.$(OBJEXT): {$(VPATH)}ruby_assert.h cont.$(OBJEXT): {$(VPATH)}ruby_assert.h
cont.$(OBJEXT): {$(VPATH)}ruby_atomic.h cont.$(OBJEXT): {$(VPATH)}ruby_atomic.h
cont.$(OBJEXT): {$(VPATH)}st.h cont.$(OBJEXT): {$(VPATH)}st.h
@ -3566,7 +3566,7 @@ debug.$(OBJEXT): {$(VPATH)}node.h
debug.$(OBJEXT): {$(VPATH)}onigmo.h debug.$(OBJEXT): {$(VPATH)}onigmo.h
debug.$(OBJEXT): {$(VPATH)}oniguruma.h debug.$(OBJEXT): {$(VPATH)}oniguruma.h
debug.$(OBJEXT): {$(VPATH)}ractor.h debug.$(OBJEXT): {$(VPATH)}ractor.h
debug.$(OBJEXT): {$(VPATH)}ractor_pub.h debug.$(OBJEXT): {$(VPATH)}ractor_core.h
debug.$(OBJEXT): {$(VPATH)}ruby_assert.h debug.$(OBJEXT): {$(VPATH)}ruby_assert.h
debug.$(OBJEXT): {$(VPATH)}ruby_atomic.h debug.$(OBJEXT): {$(VPATH)}ruby_atomic.h
debug.$(OBJEXT): {$(VPATH)}st.h debug.$(OBJEXT): {$(VPATH)}st.h
@ -4622,7 +4622,6 @@ encoding.$(OBJEXT): {$(VPATH)}missing.h
encoding.$(OBJEXT): {$(VPATH)}node.h encoding.$(OBJEXT): {$(VPATH)}node.h
encoding.$(OBJEXT): {$(VPATH)}onigmo.h encoding.$(OBJEXT): {$(VPATH)}onigmo.h
encoding.$(OBJEXT): {$(VPATH)}oniguruma.h encoding.$(OBJEXT): {$(VPATH)}oniguruma.h
encoding.$(OBJEXT): {$(VPATH)}ractor_pub.h
encoding.$(OBJEXT): {$(VPATH)}regenc.h encoding.$(OBJEXT): {$(VPATH)}regenc.h
encoding.$(OBJEXT): {$(VPATH)}ruby_assert.h encoding.$(OBJEXT): {$(VPATH)}ruby_assert.h
encoding.$(OBJEXT): {$(VPATH)}st.h encoding.$(OBJEXT): {$(VPATH)}st.h
@ -5402,7 +5401,7 @@ eval.$(OBJEXT): {$(VPATH)}probes.dmyh
eval.$(OBJEXT): {$(VPATH)}probes.h eval.$(OBJEXT): {$(VPATH)}probes.h
eval.$(OBJEXT): {$(VPATH)}probes_helper.h eval.$(OBJEXT): {$(VPATH)}probes_helper.h
eval.$(OBJEXT): {$(VPATH)}ractor.h eval.$(OBJEXT): {$(VPATH)}ractor.h
eval.$(OBJEXT): {$(VPATH)}ractor_pub.h eval.$(OBJEXT): {$(VPATH)}ractor_core.h
eval.$(OBJEXT): {$(VPATH)}ruby_assert.h eval.$(OBJEXT): {$(VPATH)}ruby_assert.h
eval.$(OBJEXT): {$(VPATH)}ruby_atomic.h eval.$(OBJEXT): {$(VPATH)}ruby_atomic.h
eval.$(OBJEXT): {$(VPATH)}st.h eval.$(OBJEXT): {$(VPATH)}st.h
@ -5824,7 +5823,7 @@ gc.$(OBJEXT): {$(VPATH)}oniguruma.h
gc.$(OBJEXT): {$(VPATH)}probes.dmyh gc.$(OBJEXT): {$(VPATH)}probes.dmyh
gc.$(OBJEXT): {$(VPATH)}probes.h gc.$(OBJEXT): {$(VPATH)}probes.h
gc.$(OBJEXT): {$(VPATH)}ractor.h gc.$(OBJEXT): {$(VPATH)}ractor.h
gc.$(OBJEXT): {$(VPATH)}ractor_pub.h gc.$(OBJEXT): {$(VPATH)}ractor_core.h
gc.$(OBJEXT): {$(VPATH)}re.h gc.$(OBJEXT): {$(VPATH)}re.h
gc.$(OBJEXT): {$(VPATH)}regenc.h gc.$(OBJEXT): {$(VPATH)}regenc.h
gc.$(OBJEXT): {$(VPATH)}regex.h gc.$(OBJEXT): {$(VPATH)}regex.h
@ -6744,7 +6743,7 @@ io.$(OBJEXT): {$(VPATH)}missing.h
io.$(OBJEXT): {$(VPATH)}node.h io.$(OBJEXT): {$(VPATH)}node.h
io.$(OBJEXT): {$(VPATH)}onigmo.h io.$(OBJEXT): {$(VPATH)}onigmo.h
io.$(OBJEXT): {$(VPATH)}oniguruma.h io.$(OBJEXT): {$(VPATH)}oniguruma.h
io.$(OBJEXT): {$(VPATH)}ractor_pub.h io.$(OBJEXT): {$(VPATH)}ractor.h
io.$(OBJEXT): {$(VPATH)}ruby_assert.h io.$(OBJEXT): {$(VPATH)}ruby_assert.h
io.$(OBJEXT): {$(VPATH)}ruby_atomic.h io.$(OBJEXT): {$(VPATH)}ruby_atomic.h
io.$(OBJEXT): {$(VPATH)}st.h io.$(OBJEXT): {$(VPATH)}st.h
@ -9756,7 +9755,7 @@ parse.$(OBJEXT): {$(VPATH)}parse.h
parse.$(OBJEXT): {$(VPATH)}parse.y parse.$(OBJEXT): {$(VPATH)}parse.y
parse.$(OBJEXT): {$(VPATH)}probes.dmyh parse.$(OBJEXT): {$(VPATH)}probes.dmyh
parse.$(OBJEXT): {$(VPATH)}probes.h parse.$(OBJEXT): {$(VPATH)}probes.h
parse.$(OBJEXT): {$(VPATH)}ractor_pub.h parse.$(OBJEXT): {$(VPATH)}ractor.h
parse.$(OBJEXT): {$(VPATH)}regenc.h parse.$(OBJEXT): {$(VPATH)}regenc.h
parse.$(OBJEXT): {$(VPATH)}regex.h parse.$(OBJEXT): {$(VPATH)}regex.h
parse.$(OBJEXT): {$(VPATH)}ruby_assert.h parse.$(OBJEXT): {$(VPATH)}ruby_assert.h
@ -10179,7 +10178,7 @@ process.$(OBJEXT): {$(VPATH)}node.h
process.$(OBJEXT): {$(VPATH)}onigmo.h process.$(OBJEXT): {$(VPATH)}onigmo.h
process.$(OBJEXT): {$(VPATH)}oniguruma.h process.$(OBJEXT): {$(VPATH)}oniguruma.h
process.$(OBJEXT): {$(VPATH)}process.c process.$(OBJEXT): {$(VPATH)}process.c
process.$(OBJEXT): {$(VPATH)}ractor_pub.h process.$(OBJEXT): {$(VPATH)}ractor.h
process.$(OBJEXT): {$(VPATH)}ruby_assert.h process.$(OBJEXT): {$(VPATH)}ruby_assert.h
process.$(OBJEXT): {$(VPATH)}ruby_atomic.h process.$(OBJEXT): {$(VPATH)}ruby_atomic.h
process.$(OBJEXT): {$(VPATH)}st.h process.$(OBJEXT): {$(VPATH)}st.h
@ -10384,7 +10383,7 @@ ractor.$(OBJEXT): {$(VPATH)}ractor.c
ractor.$(OBJEXT): {$(VPATH)}ractor.h ractor.$(OBJEXT): {$(VPATH)}ractor.h
ractor.$(OBJEXT): {$(VPATH)}ractor.rb ractor.$(OBJEXT): {$(VPATH)}ractor.rb
ractor.$(OBJEXT): {$(VPATH)}ractor.rbinc ractor.$(OBJEXT): {$(VPATH)}ractor.rbinc
ractor.$(OBJEXT): {$(VPATH)}ractor_pub.h ractor.$(OBJEXT): {$(VPATH)}ractor_core.h
ractor.$(OBJEXT): {$(VPATH)}ruby_assert.h ractor.$(OBJEXT): {$(VPATH)}ruby_assert.h
ractor.$(OBJEXT): {$(VPATH)}ruby_atomic.h ractor.$(OBJEXT): {$(VPATH)}ruby_atomic.h
ractor.$(OBJEXT): {$(VPATH)}st.h ractor.$(OBJEXT): {$(VPATH)}st.h
@ -14180,7 +14179,7 @@ thread.$(OBJEXT): {$(VPATH)}node.h
thread.$(OBJEXT): {$(VPATH)}onigmo.h thread.$(OBJEXT): {$(VPATH)}onigmo.h
thread.$(OBJEXT): {$(VPATH)}oniguruma.h thread.$(OBJEXT): {$(VPATH)}oniguruma.h
thread.$(OBJEXT): {$(VPATH)}ractor.h thread.$(OBJEXT): {$(VPATH)}ractor.h
thread.$(OBJEXT): {$(VPATH)}ractor_pub.h thread.$(OBJEXT): {$(VPATH)}ractor_core.h
thread.$(OBJEXT): {$(VPATH)}ruby_assert.h thread.$(OBJEXT): {$(VPATH)}ruby_assert.h
thread.$(OBJEXT): {$(VPATH)}ruby_atomic.h thread.$(OBJEXT): {$(VPATH)}ruby_atomic.h
thread.$(OBJEXT): {$(VPATH)}st.h thread.$(OBJEXT): {$(VPATH)}st.h
@ -14738,7 +14737,6 @@ transient_heap.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
transient_heap.$(OBJEXT): {$(VPATH)}method.h transient_heap.$(OBJEXT): {$(VPATH)}method.h
transient_heap.$(OBJEXT): {$(VPATH)}missing.h transient_heap.$(OBJEXT): {$(VPATH)}missing.h
transient_heap.$(OBJEXT): {$(VPATH)}node.h transient_heap.$(OBJEXT): {$(VPATH)}node.h
transient_heap.$(OBJEXT): {$(VPATH)}ractor_pub.h
transient_heap.$(OBJEXT): {$(VPATH)}ruby_assert.h transient_heap.$(OBJEXT): {$(VPATH)}ruby_assert.h
transient_heap.$(OBJEXT): {$(VPATH)}ruby_atomic.h transient_heap.$(OBJEXT): {$(VPATH)}ruby_atomic.h
transient_heap.$(OBJEXT): {$(VPATH)}st.h transient_heap.$(OBJEXT): {$(VPATH)}st.h
@ -15106,7 +15104,7 @@ variable.$(OBJEXT): {$(VPATH)}node.h
variable.$(OBJEXT): {$(VPATH)}onigmo.h variable.$(OBJEXT): {$(VPATH)}onigmo.h
variable.$(OBJEXT): {$(VPATH)}oniguruma.h variable.$(OBJEXT): {$(VPATH)}oniguruma.h
variable.$(OBJEXT): {$(VPATH)}ractor.h variable.$(OBJEXT): {$(VPATH)}ractor.h
variable.$(OBJEXT): {$(VPATH)}ractor_pub.h variable.$(OBJEXT): {$(VPATH)}ractor_core.h
variable.$(OBJEXT): {$(VPATH)}ruby_assert.h variable.$(OBJEXT): {$(VPATH)}ruby_assert.h
variable.$(OBJEXT): {$(VPATH)}ruby_atomic.h variable.$(OBJEXT): {$(VPATH)}ruby_atomic.h
variable.$(OBJEXT): {$(VPATH)}st.h variable.$(OBJEXT): {$(VPATH)}st.h
@ -15520,7 +15518,7 @@ vm.$(OBJEXT): {$(VPATH)}probes.dmyh
vm.$(OBJEXT): {$(VPATH)}probes.h vm.$(OBJEXT): {$(VPATH)}probes.h
vm.$(OBJEXT): {$(VPATH)}probes_helper.h vm.$(OBJEXT): {$(VPATH)}probes_helper.h
vm.$(OBJEXT): {$(VPATH)}ractor.h vm.$(OBJEXT): {$(VPATH)}ractor.h
vm.$(OBJEXT): {$(VPATH)}ractor_pub.h vm.$(OBJEXT): {$(VPATH)}ractor_core.h
vm.$(OBJEXT): {$(VPATH)}ruby_assert.h vm.$(OBJEXT): {$(VPATH)}ruby_assert.h
vm.$(OBJEXT): {$(VPATH)}ruby_atomic.h vm.$(OBJEXT): {$(VPATH)}ruby_atomic.h
vm.$(OBJEXT): {$(VPATH)}st.h vm.$(OBJEXT): {$(VPATH)}st.h
@ -15912,7 +15910,7 @@ vm_dump.$(OBJEXT): {$(VPATH)}missing.h
vm_dump.$(OBJEXT): {$(VPATH)}node.h vm_dump.$(OBJEXT): {$(VPATH)}node.h
vm_dump.$(OBJEXT): {$(VPATH)}procstat_vm.c vm_dump.$(OBJEXT): {$(VPATH)}procstat_vm.c
vm_dump.$(OBJEXT): {$(VPATH)}ractor.h vm_dump.$(OBJEXT): {$(VPATH)}ractor.h
vm_dump.$(OBJEXT): {$(VPATH)}ractor_pub.h vm_dump.$(OBJEXT): {$(VPATH)}ractor_core.h
vm_dump.$(OBJEXT): {$(VPATH)}ruby_assert.h vm_dump.$(OBJEXT): {$(VPATH)}ruby_assert.h
vm_dump.$(OBJEXT): {$(VPATH)}ruby_atomic.h vm_dump.$(OBJEXT): {$(VPATH)}ruby_atomic.h
vm_dump.$(OBJEXT): {$(VPATH)}st.h vm_dump.$(OBJEXT): {$(VPATH)}st.h
@ -16108,7 +16106,7 @@ vm_sync.$(OBJEXT): {$(VPATH)}missing.h
vm_sync.$(OBJEXT): {$(VPATH)}node.h vm_sync.$(OBJEXT): {$(VPATH)}node.h
vm_sync.$(OBJEXT): {$(VPATH)}procstat_vm.c vm_sync.$(OBJEXT): {$(VPATH)}procstat_vm.c
vm_sync.$(OBJEXT): {$(VPATH)}ractor.h vm_sync.$(OBJEXT): {$(VPATH)}ractor.h
vm_sync.$(OBJEXT): {$(VPATH)}ractor_pub.h vm_sync.$(OBJEXT): {$(VPATH)}ractor_core.h
vm_sync.$(OBJEXT): {$(VPATH)}ruby_assert.h vm_sync.$(OBJEXT): {$(VPATH)}ruby_assert.h
vm_sync.$(OBJEXT): {$(VPATH)}ruby_atomic.h vm_sync.$(OBJEXT): {$(VPATH)}ruby_atomic.h
vm_sync.$(OBJEXT): {$(VPATH)}st.h vm_sync.$(OBJEXT): {$(VPATH)}st.h

2
cont.c
View file

@ -29,7 +29,7 @@
#include "mjit.h" #include "mjit.h"
#include "vm_core.h" #include "vm_core.h"
#include "id_table.h" #include "id_table.h"
#include "ractor.h" #include "ractor_core.h"
static const int DEBUG = 0; static const int DEBUG = 0;

View file

@ -26,7 +26,7 @@
#include "vm_debug.h" #include "vm_debug.h"
#include "vm_callinfo.h" #include "vm_callinfo.h"
#include "ruby/thread_native.h" #include "ruby/thread_native.h"
#include "ractor.h" #include "ractor_core.h"
/* This is the only place struct RIMemo is actually used */ /* This is the only place struct RIMemo is actually used */
struct RIMemo { struct RIMemo {

View file

@ -26,7 +26,6 @@
#include "ruby/encoding.h" #include "ruby/encoding.h"
#include "ruby/util.h" #include "ruby/util.h"
#include "ruby_assert.h" #include "ruby_assert.h"
#include "ractor_pub.h"
#include "vm_sync.h" #include "vm_sync.h"
#ifndef ENC_DEBUG #ifndef ENC_DEBUG

2
eval.c
View file

@ -37,7 +37,7 @@
#include "probes_helper.h" #include "probes_helper.h"
#include "ruby/vm.h" #include "ruby/vm.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor.h" #include "ractor_core.h"
NORETURN(void rb_raise_jump(VALUE, VALUE)); NORETURN(void rb_raise_jump(VALUE, VALUE));
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec); void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);

View file

@ -210,6 +210,7 @@ ripper.o: $(hdrdir)/ruby/io.h
ripper.o: $(hdrdir)/ruby/missing.h ripper.o: $(hdrdir)/ruby/missing.h
ripper.o: $(hdrdir)/ruby/onigmo.h ripper.o: $(hdrdir)/ruby/onigmo.h
ripper.o: $(hdrdir)/ruby/oniguruma.h ripper.o: $(hdrdir)/ruby/oniguruma.h
ripper.o: $(hdrdir)/ruby/ractor.h
ripper.o: $(hdrdir)/ruby/regex.h ripper.o: $(hdrdir)/ruby/regex.h
ripper.o: $(hdrdir)/ruby/ruby.h ripper.o: $(hdrdir)/ruby/ruby.h
ripper.o: $(hdrdir)/ruby/st.h ripper.o: $(hdrdir)/ruby/st.h
@ -244,7 +245,6 @@ ripper.o: $(top_srcdir)/internal/variable.h
ripper.o: $(top_srcdir)/internal/vm.h ripper.o: $(top_srcdir)/internal/vm.h
ripper.o: $(top_srcdir)/internal/warnings.h ripper.o: $(top_srcdir)/internal/warnings.h
ripper.o: $(top_srcdir)/node.h ripper.o: $(top_srcdir)/node.h
ripper.o: $(top_srcdir)/ractor_pub.h
ripper.o: $(top_srcdir)/regenc.h ripper.o: $(top_srcdir)/regenc.h
ripper.o: $(top_srcdir)/ruby_assert.h ripper.o: $(top_srcdir)/ruby_assert.h
ripper.o: $(top_srcdir)/symbol.h ripper.o: $(top_srcdir)/symbol.h

2
gc.c
View file

@ -112,7 +112,7 @@
#include "vm_core.h" #include "vm_core.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "vm_callinfo.h" #include "vm_callinfo.h"
#include "ractor.h" #include "ractor_core.h"
#include "builtin.h" #include "builtin.h"

45
include/ruby/ractor.h Normal file
View file

@ -0,0 +1,45 @@
#ifndef RUBY_RACTOR_H
#define RUBY_RACTOR_H 1
/**
* @file
* @author Koichi Sasada
* @date Tue Nov 17 16:39:15 2020
* @copyright Copyright (C) 2020 Yukihiro Matsumoto
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
*/
RUBY_SYMBOL_EXPORT_BEGIN
RUBY_EXTERN VALUE rb_cRactor;
VALUE rb_ractor_stdin(void);
VALUE rb_ractor_stdout(void);
VALUE rb_ractor_stderr(void);
void rb_ractor_stdin_set(VALUE);
void rb_ractor_stdout_set(VALUE);
void rb_ractor_stderr_set(VALUE);
bool rb_ractor_shareable_p_continue(VALUE obj); // do not call it directly.
RUBY_SYMBOL_EXPORT_END
#define RB_OBJ_SHAREABLE_P(obj) FL_TEST_RAW((obj), RUBY_FL_SHAREABLE)
static inline bool
rb_ractor_shareable_p(VALUE obj)
{
if (SPECIAL_CONST_P(obj)) {
return true;
}
else if (RB_OBJ_SHAREABLE_P(obj)) {
return true;
}
else {
return rb_ractor_shareable_p_continue(obj);
}
}
#endif /* RUBY_RACTOR_H */

View file

@ -31,10 +31,14 @@ typedef union rb_thread_lock_union {
CRITICAL_SECTION crit; CRITICAL_SECTION crit;
} rb_nativethread_lock_t; } rb_nativethread_lock_t;
typedef struct rb_thread_cond_struct rb_nativethread_cond_t;
#elif defined(HAVE_PTHREAD_H) #elif defined(HAVE_PTHREAD_H)
#include <pthread.h> #include <pthread.h>
typedef pthread_t rb_nativethread_id_t; typedef pthread_t rb_nativethread_id_t;
typedef pthread_mutex_t rb_nativethread_lock_t; typedef pthread_mutex_t rb_nativethread_lock_t;
typedef pthread_cond_t rb_nativethread_cond_t;
#else #else
#error "unsupported thread type" #error "unsupported thread type"
@ -50,6 +54,19 @@ void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock); void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock); void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock);
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
void rb_native_cond_signal(rb_nativethread_cond_t *cond);
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
RUBY_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END
#endif #endif

2
io.c
View file

@ -134,7 +134,7 @@
#include "ruby/thread.h" #include "ruby/thread.h"
#include "ruby/util.h" #include "ruby/util.h"
#include "ruby_atomic.h" #include "ruby_atomic.h"
#include "ractor_pub.h" #include "ruby/ractor.h"
#if !USE_POLL #if !USE_POLL
# include "vm_core.h" # include "vm_core.h"

View file

@ -57,8 +57,8 @@ struct lex_context {
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "ruby/st.h" #include "ruby/st.h"
#include "ruby/util.h" #include "ruby/util.h"
#include "ruby/ractor.h"
#include "symbol.h" #include "symbol.h"
#include "ractor_pub.h"
#define AREF(ary, i) RARRAY_AREF(ary, i) #define AREF(ary, i) RARRAY_AREF(ary, i)

View file

@ -114,7 +114,7 @@ int initgroups(const char *, rb_gid_t);
#include "ruby/thread.h" #include "ruby/thread.h"
#include "ruby/util.h" #include "ruby/util.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor_pub.h" #include "ruby/ractor.h"
/* define system APIs */ /* define system APIs */
#ifdef _WIN32 #ifdef _WIN32

View file

@ -2,10 +2,11 @@
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "ruby/thread.h" #include "ruby/thread.h"
#include "ruby/ractor.h"
#include "ruby/thread_native.h" #include "ruby/thread_native.h"
#include "vm_core.h" #include "vm_core.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "ractor.h" #include "ractor_core.h"
#include "internal/complex.h" #include "internal/complex.h"
#include "internal/error.h" #include "internal/error.h"
#include "internal/hash.h" #include "internal/hash.h"
@ -14,7 +15,7 @@
#include "variable.h" #include "variable.h"
#include "gc.h" #include "gc.h"
static VALUE rb_cRactor; VALUE rb_cRactor;
static VALUE rb_eRactorError; static VALUE rb_eRactorError;
static VALUE rb_eRactorRemoteError; static VALUE rb_eRactorRemoteError;
static VALUE rb_eRactorMovedError; static VALUE rb_eRactorMovedError;

View file

@ -1,8 +1,8 @@
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "ruby/ractor.h"
#include "vm_core.h" #include "vm_core.h"
#include "id_table.h" #include "id_table.h"
#include "vm_debug.h" #include "vm_debug.h"
#include "ractor_pub.h"
#ifndef RACTOR_CHECK_MODE #ifndef RACTOR_CHECK_MODE
#define RACTOR_CHECK_MODE (0 || VM_CHECK_MODE || RUBY_DEBUG) #define RACTOR_CHECK_MODE (0 || VM_CHECK_MODE || RUBY_DEBUG)
@ -158,6 +158,20 @@ void rb_ractor_blocking_threads_dec(rb_ractor_t *r, const char *file, int line);
void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r); void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r);
void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r); void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r);
void rb_ractor_terminate_all(void); void rb_ractor_terminate_all(void);
bool rb_ractor_main_p_(void);
RUBY_EXTERN bool ruby_multi_ractor;
static inline bool
rb_ractor_main_p(void)
{
if (!ruby_multi_ractor) {
return true;
}
else {
return rb_ractor_main_p_();
}
}
static inline bool static inline bool
rb_ractor_status_p(rb_ractor_t *r, enum ractor_status status) rb_ractor_status_p(rb_ractor_t *r, enum ractor_status status)

View file

@ -1,52 +0,0 @@
#ifndef RACTOR_PUB_INCLUDED
#define RACTOR_PUB_INCLUDED
RUBY_EXTERN bool ruby_multi_ractor;
bool rb_ractor_main_p_(void);
static inline bool
rb_ractor_main_p(void)
{
if (!ruby_multi_ractor) {
return true;
}
else {
return rb_ractor_main_p_();
}
}
bool rb_ractor_shareable_p_continue(VALUE obj);
#define RB_OBJ_SHAREABLE_P(obj) FL_TEST_RAW((obj), RUBY_FL_SHAREABLE)
// TODO: deep frozen
static inline bool
rb_ractor_shareable_p(VALUE obj)
{
if (SPECIAL_CONST_P(obj)) {
return true;
}
else if (RB_OBJ_SHAREABLE_P(obj)) {
return true;
}
else {
return rb_ractor_shareable_p_continue(obj);
}
}
VALUE rb_ractor_make_shareable(VALUE obj);
RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_ractor_stdin(void);
VALUE rb_ractor_stdout(void);
VALUE rb_ractor_stderr(void);
void rb_ractor_stdin_set(VALUE);
void rb_ractor_stdout_set(VALUE);
void rb_ractor_stderr_set(VALUE);
RUBY_SYMBOL_EXPORT_END
#endif

View file

@ -94,7 +94,7 @@
#include "ruby/thread_native.h" #include "ruby/thread_native.h"
#include "timev.h" #include "timev.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor.h" #include "ractor_core.h"
#include "vm_debug.h" #include "vm_debug.h"
#include "vm_sync.h" #include "vm_sync.h"

View file

@ -17,8 +17,6 @@
#define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER #define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
#define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER #define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
typedef pthread_cond_t rb_nativethread_cond_t;
typedef struct native_thread_data_struct { typedef struct native_thread_data_struct {
union { union {
struct list_node ubf; struct list_node ubf;
@ -39,18 +37,6 @@ typedef struct native_thread_data_struct {
} cond; } cond;
} native_thread_data_t; } native_thread_data_t;
void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock);
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
void rb_native_cond_signal(rb_nativethread_cond_t *cond);
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
#undef except #undef except
#undef try #undef try
#undef leave #undef leave

View file

@ -52,12 +52,12 @@ w32_error(const char *func)
} }
static int static int
w32_mutex_lock(HANDLE lock) w32_mutex_lock(HANDLE lock, bool try)
{ {
DWORD result; DWORD result;
while (1) { while (1) {
thread_debug("rb_native_mutex_lock: %p\n", lock); thread_debug("rb_native_mutex_lock: %p\n", lock);
result = w32_wait_events(&lock, 1, INFINITE, 0); result = w32_wait_events(&lock, 1, try ? 0 : INFINITE, 0);
switch (result) { switch (result) {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
/* get mutex object */ /* get mutex object */
@ -70,7 +70,7 @@ w32_mutex_lock(HANDLE lock)
return 0; return 0;
case WAIT_TIMEOUT: case WAIT_TIMEOUT:
thread_debug("timeout mutex: %p\n", lock); thread_debug("timeout mutex: %p\n", lock);
break; return EBUSY;
case WAIT_ABANDONED: case WAIT_ABANDONED:
rb_bug("win32_mutex_lock: WAIT_ABANDONED"); rb_bug("win32_mutex_lock: WAIT_ABANDONED");
break; break;
@ -97,7 +97,7 @@ w32_mutex_create(void)
static void static void
gvl_acquire(rb_global_vm_lock_t *gvl, rb_thread_t *th) gvl_acquire(rb_global_vm_lock_t *gvl, rb_thread_t *th)
{ {
w32_mutex_lock(gvl->lock); w32_mutex_lock(gvl->lock, false);
if (GVL_DEBUG) fprintf(stderr, "gvl acquire (%p): acquire\n", th); if (GVL_DEBUG) fprintf(stderr, "gvl acquire (%p): acquire\n", th);
} }
@ -323,12 +323,22 @@ void
rb_native_mutex_lock(rb_nativethread_lock_t *lock) rb_native_mutex_lock(rb_nativethread_lock_t *lock)
{ {
#if USE_WIN32_MUTEX #if USE_WIN32_MUTEX
w32_mutex_lock(lock->mutex); w32_mutex_lock(lock->mutex, false);
#else #else
EnterCriticalSection(&lock->crit); EnterCriticalSection(&lock->crit);
#endif #endif
} }
int
rb_native_mutex_trylock(rb_nativethread_lock_t *lock)
{
#if USE_WIN32_MUTEX
return w32_mutex_lock(lock->mutex, true);
#else
return TryEnterCriticalSection(&lock->crit) == 0 ? EBUSY : 0;
#endif
}
void void
rb_native_mutex_unlock(rb_nativethread_lock_t *lock) rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
{ {
@ -340,27 +350,6 @@ rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
#endif #endif
} }
RBIMPL_ATTR_MAYBE_UNUSED()
static int
native_mutex_trylock(rb_nativethread_lock_t *lock)
{
#if USE_WIN32_MUTEX
int result;
thread_debug("native_mutex_trylock: %p\n", lock->mutex);
result = w32_wait_events(&lock->mutex, 1, 1, 0);
thread_debug("native_mutex_trylock result: %d\n", result);
switch (result) {
case WAIT_OBJECT_0:
return 0;
case WAIT_TIMEOUT:
return EBUSY;
}
return EINVAL;
#else
return TryEnterCriticalSection(&lock->crit) == 0;
#endif
}
void void
rb_native_mutex_initialize(rb_nativethread_lock_t *lock) rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
{ {

View file

@ -54,17 +54,6 @@ native_tls_set(native_tls_key_t key, void *ptr)
} }
} }
void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
void rb_native_cond_signal(rb_nativethread_cond_t *cond);
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
RUBY_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN
RUBY_EXTERN native_tls_key_t ruby_current_ec_key; RUBY_EXTERN native_tls_key_t ruby_current_ec_key;
RUBY_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END

View file

@ -36,7 +36,7 @@
#include "transient_heap.h" #include "transient_heap.h"
#include "variable.h" #include "variable.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor_pub.h" #include "ractor_core.h"
#include "vm_sync.h" #include "vm_sync.h"
typedef void rb_gvar_compact_t(void *var); typedef void rb_gvar_compact_t(void *var);

2
vm.c
View file

@ -35,7 +35,7 @@
#include "vm_debug.h" #include "vm_debug.h"
#include "vm_exec.h" #include "vm_exec.h"
#include "vm_insnhelper.h" #include "vm_insnhelper.h"
#include "ractor.h" #include "ractor_core.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "builtin.h" #include "builtin.h"

View file

@ -35,7 +35,7 @@
#include "internal/vm.h" #include "internal/vm.h"
#include "iseq.h" #include "iseq.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor.h" #include "ractor_core.h"
#define MAX_POSBUF 128 #define MAX_POSBUF 128

View file

@ -1,6 +1,6 @@
#include "vm_core.h" #include "vm_core.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "ractor.h" #include "ractor_core.h"
#include "vm_debug.h" #include "vm_debug.h"
#include "gc.h" #include "gc.h"