summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-11-17 16:40:47 +0900
committerKoichi Sasada <ko1@atdot.net>2020-11-18 03:52:41 +0900
commit5e3259ea7490a2542d78c433eb8c9d44c7819e61 (patch)
tree1a280e725a2c66ca776086661e3b707fd73f4577 /include
parent0683912db888b0421ce4c40ad450ccf75ad7e3f4 (diff)
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)
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3775
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ractor.h45
-rw-r--r--include/ruby/thread_native.h17
2 files changed, 62 insertions, 0 deletions
diff --git a/include/ruby/ractor.h b/include/ruby/ractor.h
new file mode 100644
index 0000000000..6908c0a453
--- /dev/null
+++ b/include/ruby/ractor.h
@@ -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 */
diff --git a/include/ruby/thread_native.h b/include/ruby/thread_native.h
index 0285c8ff40..7e08c2e97f 100644
--- a/include/ruby/thread_native.h
+++ b/include/ruby/thread_native.h
@@ -31,10 +31,14 @@ typedef union rb_thread_lock_union {
CRITICAL_SECTION crit;
} rb_nativethread_lock_t;
+typedef struct rb_thread_cond_struct rb_nativethread_cond_t;
+
#elif defined(HAVE_PTHREAD_H)
+
#include <pthread.h>
typedef pthread_t rb_nativethread_id_t;
typedef pthread_mutex_t rb_nativethread_lock_t;
+typedef pthread_cond_t rb_nativethread_cond_t;
#else
#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_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
#endif