Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[io] only sync buffers for IO types where it makes sense

  • Loading branch information...
commit 10d8851b64972a37e051815ca312fac9dbbf4d83 1 parent 28129d6
@cotto cotto authored
View
2  include/parrot/io.h
@@ -63,6 +63,8 @@
#define PIO_VF_AWAYS_READABLE 0x0010 /* Handle can always be read */
#define PIO_VF_MULTI_READABLE 0x0020 /* Can perform multiple low-level read
operations to satisfy a large request */
+#define PIO_VF_SYNC_IO 0x0040 /* This type needs synchronization
+ before r/w operations due to buffering */
/*
* pioctl argument constants. These don't have to
View
3  src/io/filehandle.c
@@ -228,7 +228,8 @@ io_filehandle_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTV
vtable->flags = PIO_VF_DEFAULT_READ_BUF
| PIO_VF_DEFAULT_WRITE_BUF
| PIO_VF_MULTI_READABLE
- | PIO_VF_FLUSH_ON_CLOSE;
+ | PIO_VF_FLUSH_ON_CLOSE
+ | PIO_VF_SYNC_IO;
vtable->name = "FileHandle";
vtable->read_b = io_filehandle_read_b;
vtable->write_b = io_filehandle_write_b;
View
3  src/io/stringhandle.c
@@ -230,8 +230,9 @@ io_stringhandle_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), IN
vtable->flags =
PIO_VF_PATH_NOT_REQUIRED | /* StringHandle does not require a path to open */
PIO_VF_MULTI_READABLE | /* Multiple reads will not hang */
- PIO_VF_AWAYS_READABLE; /* StringHandle can be read when closed or not in
+ PIO_VF_AWAYS_READABLE | /* StringHandle can be read when closed or not in
read mode */
+ PIO_VF_SYNC_IO;
vtable->name = "StringHandle";
vtable->read_b = io_stringhandle_read_b;
vtable->write_b = io_stringhandle_write_b;
View
4 src/io/utilities.c
@@ -513,7 +513,7 @@ io_sync_buffers_for_read(PARROT_INTERP, ARGMOD(PMC *handle),
and advance the cursor before we attempt to read. Otherwise we'll be
reading data from the buffer that has already been overwritten, from a
position several bytes before where we're supposed to be. */
- if (write_buffer && !BUFFER_IS_EMPTY(write_buffer)) {
+ if (write_buffer && !BUFFER_IS_EMPTY(write_buffer) && (vtable->flags & PIO_VF_SYNC_IO)) {
const size_t bytes_written = Parrot_io_buffer_flush(interp, write_buffer,
handle, vtable);
PARROT_ASSERT(BUFFER_IS_EMPTY(write_buffer));
@@ -548,7 +548,7 @@ io_sync_buffers_for_write(PARROT_INTERP, ARGMOD(PMC *handle),
current cursor. We need to clear the read buffer and reset the on-disk
position to match what we expect it to be, so the written data goes
to the correct place */
- if (read_buffer && !BUFFER_IS_EMPTY(read_buffer)) {
+ if (read_buffer && !BUFFER_IS_EMPTY(read_buffer) && (vtable->flags & PIO_VF_SYNC_IO)) {
const size_t buffer_size = BUFFER_USED_SIZE(read_buffer);
Parrot_io_buffer_clear(interp, read_buffer);
vtable->seek(interp, handle, -(PIOOFF_T)buffer_size, SEEK_CUR);
Please sign in to comment.
Something went wrong with that request. Please try again.