summaryrefslogtreecommitdiff
path: root/internal/io.h
diff options
context:
space:
mode:
Diffstat (limited to 'internal/io.h')
-rw-r--r--internal/io.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/internal/io.h b/internal/io.h
index b4efa174a1..2110f0b087 100644
--- a/internal/io.h
+++ b/internal/io.h
@@ -14,10 +14,21 @@
struct rb_io;
#include "ruby/io.h" /* for rb_io_t */
+#include "ccan/list/list.h"
+#include "serial.h"
#define IO_WITHOUT_GVL(func, arg) rb_nogvl(func, arg, RUBY_UBF_IO, 0, RB_NOGVL_OFFLOAD_SAFE)
#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)
+// Represents an in-flight blocking operation:
+struct rb_io_blocking_operation {
+ // The linked list data structure.
+ struct ccan_list_node list;
+
+ // The execution context of the blocking operation.
+ struct rb_execution_context_struct *ec;
+};
+
/** Ruby's IO, metadata and buffers. */
struct rb_io {
@@ -31,7 +42,7 @@ struct rb_io {
int fd;
/** mode flags: FMODE_XXXs */
- int mode;
+ enum rb_io_mode mode;
/** child's pid (for pipes) */
rb_pid_t pid;
@@ -111,6 +122,18 @@ struct rb_io {
* The timeout associated with this IO when performing blocking operations.
*/
VALUE timeout;
+
+ /**
+ * Threads that are performing a blocking operation without the GVL using
+ * this IO. On calling IO#close, these threads will be interrupted so that
+ * the operation can be cancelled.
+ */
+ struct ccan_list_head blocking_operations;
+ struct rb_execution_context_struct *closing_ec;
+ VALUE wakeup_mutex;
+
+ // The fork generation of the blocking operations list.
+ rb_serial_t fork_generation;
};
/* io.c */
@@ -119,17 +142,15 @@ void rb_stdio_set_default_encoding(void);
VALUE rb_io_flush_raw(VALUE, int);
size_t rb_io_memsize(const rb_io_t *);
int rb_stderr_tty_p(void);
-void rb_io_fptr_finalize_internal(void *ptr);
-#ifdef rb_io_fptr_finalize
-# undef rb_io_fptr_finalize
-#endif
-#define rb_io_fptr_finalize rb_io_fptr_finalize_internal
VALUE rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt);
VALUE rb_io_prep_stdin(void);
VALUE rb_io_prep_stdout(void);
VALUE rb_io_prep_stderr(void);
+int rb_io_notify_close(struct rb_io *fptr);
+bool rb_io_fptr_finalize_closed(struct rb_io *fptr);
+
RUBY_SYMBOL_EXPORT_BEGIN
/* io.c (export) */
void rb_maygvl_fd_fix_cloexec(int fd);