Skip to content

Commit 122dabc

Browse files
committed
WIP
1 parent e907139 commit 122dabc

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

include/ruby/io.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,8 @@ VALUE rb_io_check_io(VALUE io);
674674
* @param[in] io An IO.
675675
* @param[in] function A function to call.
676676
* @param[in] data Data to pass to the function.
677-
* @param[in] flags Flags (must be 0, reserved for later use).
678677
*/
679-
VALUE rb_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument, int flags);
678+
VALUE rb_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument);
680679

681680
/**
682681
* Queries the tied IO for writing. An IO can be duplexed. Fine. The thing

internal/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, in
7777
VALUE rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, int events);
7878

7979
// Invoke the given function, with the specified argument, in a way that `IO#close` from another execution context can interrupt it.
80-
VALUE rb_thread_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument, int flags);
80+
VALUE rb_thread_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument);
8181

8282
/* thread.c (export) */
8383
int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */

io.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,15 @@ VALUE rb_io_blocking_region(struct rb_io *io, rb_blocking_function_t *function,
234234
}
235235

236236
VALUE
237-
rb_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument, int flags)
237+
rb_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument)
238238
{
239-
return rb_thread_io_interruptable_operation(self, function, argument, flags);
239+
VALUE scheduler = rb_fiber_scheduler_current();
240+
241+
if (scheduler == Qnil) {
242+
return function(argument);
243+
} else {
244+
return rb_thread_io_interruptable_operation(self, function, argument);
245+
}
240246
}
241247

242248
VALUE
@@ -250,7 +256,7 @@ io_interruptable_operation(VALUE self)
250256
{
251257
VALUE block = rb_block_proc();
252258

253-
return rb_io_interruptable_operation(self, io_interruptable_operation_begin, block, 0);
259+
return rb_io_interruptable_operation(self, io_interruptable_operation_begin, block);
254260
}
255261

256262
struct argf {

thread.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ rb_thread_io_interruptable_operation_ensure(VALUE _argument)
17421742
}
17431743

17441744
VALUE
1745-
rb_thread_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument, int flags)
1745+
rb_thread_io_interruptable_operation(VALUE self, VALUE(*function)(VALUE), VALUE argument)
17461746
{
17471747
struct rb_io *io;
17481748
RB_IO_POINTER(self, io);
@@ -2665,7 +2665,7 @@ rb_ec_reset_raised(rb_execution_context_t *ec)
26652665
int
26662666
rb_notify_fd_close(int fd, struct rb_io_close_wait_list *busy)
26672667
{
2668-
fprintf(stderr, "rb_notify_fd_close(%d) pid=%d\n", fd, getpid());
2668+
// fprintf(stderr, "rb_notify_fd_close(%d) pid=%d\n", fd, getpid());
26692669
rb_vm_t *vm = GET_THREAD()->vm;
26702670
struct waiting_fd *wfd = 0, *next;
26712671
ccan_list_head_init(&busy->pending_fd_users);
@@ -2689,7 +2689,7 @@ rb_notify_fd_close(int fd, struct rb_io_close_wait_list *busy)
26892689
if (th->scheduler != Qnil) {
26902690
rb_fiber_scheduler_fiber_interrupt(th->scheduler, rb_fiberptr_self(ec->fiber_ptr), error);
26912691
} else {
2692-
fprintf(stderr, "rb_notify_fd_close: Interrupting thread %p\n", (void *)th);
2692+
// fprintf(stderr, "rb_notify_fd_close: Interrupting thread %p\n", (void *)th);
26932693
rb_threadptr_pending_interrupt_enque(th, error);
26942694
rb_threadptr_interrupt(th);
26952695
}

0 commit comments

Comments
 (0)