Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ce6a12

Browse files
committed
Use per-io blocking operation list.
1 parent c74cb6c commit 0ce6a12

File tree

12 files changed

+192
-402
lines changed

12 files changed

+192
-402
lines changed

common.mk

+11
Original file line numberDiff line numberDiff line change
@@ -7075,6 +7075,7 @@ file.$(OBJEXT): $(CCAN_DIR)/str/str.h
70757075
file.$(OBJEXT): $(hdrdir)/ruby/ruby.h
70767076
file.$(OBJEXT): $(hdrdir)/ruby/version.h
70777077
file.$(OBJEXT): $(top_srcdir)/internal/array.h
7078+
file.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h
70787079
file.$(OBJEXT): $(top_srcdir)/internal/class.h
70797080
file.$(OBJEXT): $(top_srcdir)/internal/compilers.h
70807081
file.$(OBJEXT): $(top_srcdir)/internal/dir.h
@@ -7086,6 +7087,7 @@ file.$(OBJEXT): $(top_srcdir)/internal/io.h
70867087
file.$(OBJEXT): $(top_srcdir)/internal/load.h
70877088
file.$(OBJEXT): $(top_srcdir)/internal/object.h
70887089
file.$(OBJEXT): $(top_srcdir)/internal/process.h
7090+
file.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
70897091
file.$(OBJEXT): $(top_srcdir)/internal/serial.h
70907092
file.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
70917093
file.$(OBJEXT): $(top_srcdir)/internal/string.h
@@ -7094,6 +7096,7 @@ file.$(OBJEXT): $(top_srcdir)/internal/variable.h
70947096
file.$(OBJEXT): $(top_srcdir)/internal/vm.h
70957097
file.$(OBJEXT): $(top_srcdir)/internal/warnings.h
70967098
file.$(OBJEXT): {$(VPATH)}assert.h
7099+
file.$(OBJEXT): {$(VPATH)}atomic.h
70977100
file.$(OBJEXT): {$(VPATH)}backward/2/assume.h
70987101
file.$(OBJEXT): {$(VPATH)}backward/2/attributes.h
70997102
file.$(OBJEXT): {$(VPATH)}backward/2/bool.h
@@ -7264,15 +7267,23 @@ file.$(OBJEXT): {$(VPATH)}internal/variable.h
72647267
file.$(OBJEXT): {$(VPATH)}internal/warning_push.h
72657268
file.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
72667269
file.$(OBJEXT): {$(VPATH)}io.h
7270+
file.$(OBJEXT): {$(VPATH)}method.h
72677271
file.$(OBJEXT): {$(VPATH)}missing.h
7272+
file.$(OBJEXT): {$(VPATH)}node.h
72687273
file.$(OBJEXT): {$(VPATH)}onigmo.h
72697274
file.$(OBJEXT): {$(VPATH)}oniguruma.h
7275+
file.$(OBJEXT): {$(VPATH)}ruby_assert.h
7276+
file.$(OBJEXT): {$(VPATH)}ruby_atomic.h
7277+
file.$(OBJEXT): {$(VPATH)}rubyparser.h
72707278
file.$(OBJEXT): {$(VPATH)}shape.h
72717279
file.$(OBJEXT): {$(VPATH)}st.h
72727280
file.$(OBJEXT): {$(VPATH)}subst.h
72737281
file.$(OBJEXT): {$(VPATH)}thread.h
7282+
file.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
72747283
file.$(OBJEXT): {$(VPATH)}thread_native.h
72757284
file.$(OBJEXT): {$(VPATH)}util.h
7285+
file.$(OBJEXT): {$(VPATH)}vm_core.h
7286+
file.$(OBJEXT): {$(VPATH)}vm_opts.h
72767287
gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
72777288
gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
72787289
gc.$(OBJEXT): $(CCAN_DIR)/list/list.h

ext/-test-/thread_fd/depend

-161
This file was deleted.

ext/-test-/thread_fd/extconf.rb

-2
This file was deleted.

ext/-test-/thread_fd/thread_fd.c

-30
This file was deleted.

gc.c

+1
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,7 @@ rb_gc_mark_children(void *objspace, VALUE obj)
28382838
gc_mark_internal(RFILE(obj)->fptr->encs.ecopts);
28392839
gc_mark_internal(RFILE(obj)->fptr->write_lock);
28402840
gc_mark_internal(RFILE(obj)->fptr->timeout);
2841+
gc_mark_internal(RFILE(obj)->fptr->wakeup_mutex);
28412842
}
28422843
break;
28432844

internal/io.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,23 @@
1313
#define HAVE_RB_IO_T
1414
struct rb_io;
1515

16-
#include "ruby/io.h" /* for rb_io_t */
16+
#include "ruby/io.h"
17+
18+
#include "vm_core.h"
19+
#include "ccan/list/list.h"
1720

1821
#define IO_WITHOUT_GVL(func, arg) rb_nogvl(func, arg, RUBY_UBF_IO, 0, RB_NOGVL_OFFLOAD_SAFE)
1922
#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)
2023

24+
// Represents an in-flight blocking operation:
25+
struct rb_io_blocking_operation_node {
26+
// The linked list data structure.
27+
struct ccan_list_node list;
28+
29+
// The execution context of the blocking operation:
30+
rb_execution_context_t *ec;
31+
};
32+
2133
/** Ruby's IO, metadata and buffers. */
2234
struct rb_io {
2335

@@ -111,6 +123,15 @@ struct rb_io {
111123
* The timeout associated with this IO when performing blocking operations.
112124
*/
113125
VALUE timeout;
126+
127+
/**
128+
* Threads that are performing a blocking operation without the GVL using
129+
* this IO. On calling IO#close, these threads will be interrupted so that
130+
* the operation can be cancelled.
131+
*/
132+
struct ccan_list_head blocking_operations;
133+
rb_execution_context_t *closing_ec;
134+
VALUE wakeup_mutex;
114135
};
115136

116137
/* io.c */
@@ -125,6 +146,9 @@ VALUE rb_io_prep_stdin(void);
125146
VALUE rb_io_prep_stdout(void);
126147
VALUE rb_io_prep_stderr(void);
127148

149+
int rb_io_notify_close(struct rb_io *fptr);
150+
int rb_io_fptr_finalize(struct rb_io *fptr);
151+
128152
RUBY_SYMBOL_EXPORT_BEGIN
129153
/* io.c (export) */
130154
void rb_maygvl_fd_fix_cloexec(int fd);

internal/thread.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ccan/list/list.h" /* for list in rb_io_close_wait_list */
1414

1515
struct rb_thread_struct; /* in vm_core.h */
16+
struct rb_io;
1617

1718
#define RB_VM_SAVE_MACHINE_CONTEXT(th) \
1819
do { \
@@ -58,14 +59,10 @@ void ruby_mn_threads_params(void);
5859
int rb_thread_io_wait(struct rb_io *io, int events, struct timeval * timeout);
5960
int rb_thread_wait_for_single_fd(int fd, int events, struct timeval * timeout);
6061

61-
struct rb_io_close_wait_list {
62-
struct ccan_list_head pending_fd_users;
63-
VALUE closing_thread;
64-
VALUE closing_fiber;
65-
VALUE wakeup_mutex;
66-
};
67-
int rb_notify_fd_close(int fd, struct rb_io_close_wait_list *busy);
68-
void rb_notify_fd_close_wait(struct rb_io_close_wait_list *busy);
62+
63+
64+
int rb_thread_io_close(struct rb_io *);
65+
void rb_thread_io_close_wait(struct rb_io *);
6966

7067
void rb_ec_check_ints(struct rb_execution_context_struct *ec);
7168

0 commit comments

Comments
 (0)