summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-27 05:36:02 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-27 05:36:02 +0000
commitfc9cc7440a44cfbb188f875e71095d7e49c22f51 (patch)
tree92f771a6ed0dc8834d06078ed96e53187c9a8bea /io.c
parent5458a384eaa22b3427dc81a2c8e4c4599123e805 (diff)
* io.c (io_fflush): checks wbuf modification by other threads.
not perfect. it need locks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/io.c b/io.c
index b5641b2e78..f9a41f3aee 100644
--- a/io.c
+++ b/io.c
@@ -526,24 +526,31 @@ io_fflush(rb_io_t *fptr)
return 0;
wbuf_off = fptr->wbuf_off;
wbuf_len = fptr->wbuf_len;
- l = fptr->wbuf_len;
+ l = wbuf_len;
if (PIPE_BUF < l &&
!rb_thread_critical &&
!rb_thread_alone() &&
wsplit_p(fptr)) {
l = PIPE_BUF;
}
- r = rb_write_internal(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
- /* xxx: other threads may modify wbuf */
+ r = rb_write_internal(fptr->fd, fptr->wbuf+wbuf_off, l);
+ if (wbuf_off != fptr->wbuf_off || fptr->wbuf_len < wbuf_len) {
+ /* xxx: Other threads modified wbuf in non-append operation.
+ * This condition can be false negative if other threads
+ * flush this IO and fill the buffer.
+ * A lock is required, definitely.
+ */
+ goto retry;
+ }
rb_io_check_closed(fptr);
- if (r == fptr->wbuf_len) {
+ if (fptr->wbuf_len <= r) {
fptr->wbuf_off = 0;
fptr->wbuf_len = 0;
return 0;
}
if (0 <= r) {
- fptr->wbuf_off = (wbuf_off += r);
- fptr->wbuf_len = (wbuf_len -= r);
+ fptr->wbuf_off = r;
+ fptr->wbuf_len = r;
errno = EAGAIN;
}
if (rb_io_wait_writable(fptr->fd)) {
@@ -702,7 +709,7 @@ io_fwrite(VALUE str, rb_io_t *fptr)
l = PIPE_BUF;
}
r = rb_write_internal(fptr->fd, RSTRING_PTR(str)+offset, l);
- /* xxx: signal handler may modify given string. */
+ /* xxx: other threads may modify given string. */
if (r == n) return len;
if (0 <= r) {
offset += r;
@@ -1683,7 +1690,6 @@ appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE *strp,
long last = 0, len = (c != EOF);
if (limit > 0 && pending > limit) pending = limit;
- again:
e = memchr(p, delim, pending);
if (e) pending = e - p + 1;
len += pending;