summaryrefslogtreecommitdiff
path: root/io_buffer.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2023-03-31 00:48:55 +1300
committerGitHub <noreply@github.com>2023-03-31 00:48:55 +1300
commit648870b5c577239b3274b0b48c82fb74910dfabf (patch)
treef944e0a1919bcb46537e1f3bd522beee9e72288c /io_buffer.c
parent6f122965cf8704f019445faead58040e9be2effb (diff)
downloadruby-648870b5c577239b3274b0b48c82fb74910dfabf.tar.gz
Support `IO#pread` / `IO#pwrite` using fiber scheduler. (#7594)
* Skip test if non-blocking file IO is not supported.
Diffstat (limited to 'io_buffer.c')
-rw-r--r--io_buffer.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/io_buffer.c b/io_buffer.c
index 2fc7ac8a80..4a08811185 100644
--- a/io_buffer.c
+++ b/io_buffer.c
@@ -1001,17 +1001,23 @@ rb_io_buffer_lock(VALUE self)
return self;
}
-VALUE
-rb_io_buffer_unlock(VALUE self)
+static void
+io_buffer_unlock(struct rb_io_buffer *data)
{
- struct rb_io_buffer *data = NULL;
- TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
-
if (!(data->flags & RB_IO_BUFFER_LOCKED)) {
rb_raise(rb_eIOBufferLockedError, "Buffer not locked!");
}
data->flags &= ~RB_IO_BUFFER_LOCKED;
+}
+
+VALUE
+rb_io_buffer_unlock(VALUE self)
+{
+ struct rb_io_buffer *data = NULL;
+ TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
+
+ io_buffer_unlock(data);
return self;
}
@@ -1123,6 +1129,17 @@ rb_io_buffer_free(VALUE self)
return self;
}
+VALUE rb_io_buffer_free_locked(VALUE self)
+{
+ struct rb_io_buffer *data = NULL;
+ TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
+
+ io_buffer_unlock(data);
+ io_buffer_free(data);
+
+ return self;
+}
+
// Validate that access to the buffer is within bounds, assuming you want to
// access length bytes from the specified offset.
static inline void