Skip to content

Commit 498cf35

Browse files
committed
Make waiting_fd behaviour per-IO.
1 parent d046c0a commit 498cf35

File tree

13 files changed

+199
-376
lines changed

13 files changed

+199
-376
lines changed

common.mk

+11
Original file line numberDiff line numberDiff line change
@@ -7125,6 +7125,7 @@ file.$(OBJEXT): $(CCAN_DIR)/str/str.h
71257125
file.$(OBJEXT): $(hdrdir)/ruby/ruby.h
71267126
file.$(OBJEXT): $(hdrdir)/ruby/version.h
71277127
file.$(OBJEXT): $(top_srcdir)/internal/array.h
7128+
file.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h
71287129
file.$(OBJEXT): $(top_srcdir)/internal/class.h
71297130
file.$(OBJEXT): $(top_srcdir)/internal/compilers.h
71307131
file.$(OBJEXT): $(top_srcdir)/internal/dir.h
@@ -7136,6 +7137,7 @@ file.$(OBJEXT): $(top_srcdir)/internal/io.h
71367137
file.$(OBJEXT): $(top_srcdir)/internal/load.h
71377138
file.$(OBJEXT): $(top_srcdir)/internal/object.h
71387139
file.$(OBJEXT): $(top_srcdir)/internal/process.h
7140+
file.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
71397141
file.$(OBJEXT): $(top_srcdir)/internal/serial.h
71407142
file.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
71417143
file.$(OBJEXT): $(top_srcdir)/internal/string.h
@@ -7144,6 +7146,7 @@ file.$(OBJEXT): $(top_srcdir)/internal/variable.h
71447146
file.$(OBJEXT): $(top_srcdir)/internal/vm.h
71457147
file.$(OBJEXT): $(top_srcdir)/internal/warnings.h
71467148
file.$(OBJEXT): {$(VPATH)}assert.h
7149+
file.$(OBJEXT): {$(VPATH)}atomic.h
71477150
file.$(OBJEXT): {$(VPATH)}backward/2/assume.h
71487151
file.$(OBJEXT): {$(VPATH)}backward/2/attributes.h
71497152
file.$(OBJEXT): {$(VPATH)}backward/2/bool.h
@@ -7314,15 +7317,23 @@ file.$(OBJEXT): {$(VPATH)}internal/variable.h
73147317
file.$(OBJEXT): {$(VPATH)}internal/warning_push.h
73157318
file.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
73167319
file.$(OBJEXT): {$(VPATH)}io.h
7320+
file.$(OBJEXT): {$(VPATH)}method.h
73177321
file.$(OBJEXT): {$(VPATH)}missing.h
7322+
file.$(OBJEXT): {$(VPATH)}node.h
73187323
file.$(OBJEXT): {$(VPATH)}onigmo.h
73197324
file.$(OBJEXT): {$(VPATH)}oniguruma.h
7325+
file.$(OBJEXT): {$(VPATH)}ruby_assert.h
7326+
file.$(OBJEXT): {$(VPATH)}ruby_atomic.h
7327+
file.$(OBJEXT): {$(VPATH)}rubyparser.h
73207328
file.$(OBJEXT): {$(VPATH)}shape.h
73217329
file.$(OBJEXT): {$(VPATH)}st.h
73227330
file.$(OBJEXT): {$(VPATH)}subst.h
73237331
file.$(OBJEXT): {$(VPATH)}thread.h
7332+
file.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
73247333
file.$(OBJEXT): {$(VPATH)}thread_native.h
73257334
file.$(OBJEXT): {$(VPATH)}util.h
7335+
file.$(OBJEXT): {$(VPATH)}vm_core.h
7336+
file.$(OBJEXT): {$(VPATH)}vm_opts.h
73267337
gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
73277338
gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
73287339
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

+3
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,7 @@ rb_gc_mark_children(void *objspace, VALUE obj)
28362836
gc_mark_internal(RFILE(obj)->fptr->encs.ecopts);
28372837
gc_mark_internal(RFILE(obj)->fptr->write_lock);
28382838
gc_mark_internal(RFILE(obj)->fptr->timeout);
2839+
gc_mark_internal(RFILE(obj)->fptr->wakeup_mutex);
28392840
}
28402841
break;
28412842

@@ -3746,6 +3747,8 @@ rb_gc_update_object_references(void *objspace, VALUE obj)
37463747
UPDATE_IF_MOVED(objspace, RFILE(obj)->fptr->writeconv_pre_ecopts);
37473748
UPDATE_IF_MOVED(objspace, RFILE(obj)->fptr->encs.ecopts);
37483749
UPDATE_IF_MOVED(objspace, RFILE(obj)->fptr->write_lock);
3750+
UPDATE_IF_MOVED(objspace, RFILE(obj)->fptr->timeout);
3751+
UPDATE_IF_MOVED(objspace, RFILE(obj)->fptr->wakeup_mutex);
37493752
}
37503753
break;
37513754
case T_REGEXP:

internal/io.h

+23-2
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 {
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,7 +146,7 @@ VALUE rb_io_prep_stdin(void);
125146
VALUE rb_io_prep_stdout(void);
126147
VALUE rb_io_prep_stderr(void);
127148

128-
int rb_io_fptr_finalize(struct rb_io *fptr);
149+
int rb_io_notify_close(struct rb_io *fptr);
129150

130151
RUBY_SYMBOL_EXPORT_BEGIN
131152
/* io.c (export) */

internal/thread.h

+3-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,8 @@ 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+
size_t rb_thread_io_close(struct rb_io *);
63+
void rb_thread_io_close_wait(struct rb_io *);
6964

7065
void rb_ec_check_ints(struct rb_execution_context_struct *ec);
7166

0 commit comments

Comments
 (0)