Last active
December 14, 2015 03:28
-
-
Save cotto/5020729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/parrot/io.h b/include/parrot/io.h | |
index 42b9f44..9fdfd2f 100644 | |
--- a/include/parrot/io.h | |
+++ b/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 */ | |
/* | |
* pioctl argument constants. These don't have to | |
diff --git a/src/io/filehandle.c b/src/io/filehandle.c | |
index 8167f3a..a769336 100644 | |
--- a/src/io/filehandle.c | |
+++ b/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; | |
diff --git a/src/io/stringhandle.c b/src/io/stringhandle.c | |
index ded7af2..5e9b0c5 100644 | |
--- a/src/io/stringhandle.c | |
+++ b/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; | |
diff --git a/src/io/utilities.c b/src/io/utilities.c | |
index 0891607..d710895 100644 | |
--- a/src/io/utilities.c | |
+++ b/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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment