diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-18 01:00:23 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-18 01:00:23 +0000 |
commit | 2b2b77d7a7afc91773324d0cde1c81a746b5baf1 (patch) | |
tree | d023c094a62f86757a19c0243670661f63146bd4 | |
parent | 227668959539a269b4a8186b1fdb92a5716bf6d3 (diff) |
* rubyio.h (FMODE_WSPLIT, FMODE_WSPLIT_INITIALIZED): new constant.
* io.c (wsplit_p): new function.
(io_fflush): split writing data by PIPE_BUF if wsplit_p is true in
multi-threaded mode.
(io_fwrite): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | io.c | 30 | ||||
-rw-r--r-- | rubyio.h | 2 |
3 files changed, 38 insertions, 2 deletions
@@ -1,3 +1,11 @@ +Mon Jul 18 09:36:25 2005 Tanaka Akira <akr@m17n.org> + + * rubyio.h (FMODE_WSPLIT, FMODE_WSPLIT_INITIALIZED): new constant. + + * io.c (wsplit_p): new function. + (io_fwrite): split writing data by PIPE_BUF if wsplit_p is true in + multi-threaded mode. + Sun Jul 17 13:46:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/io/wait/extconf.rb, ext/io/wait/wait.c: Win32 platforms support. @@ -388,13 +388,32 @@ rb_io_wait_writable(f) } } +static int +wsplit_p(OpenFile *fptr) +{ + FILE *f = GetWriteFile(fptr); + int r; + if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) { + struct stat buf; + if (fstat(fileno(f), &buf) == 0 && + !(S_ISREG(buf.st_mode) || + S_ISDIR(buf.st_mode)) && + (r = fcntl(fileno(f), F_GETFL)) != -1 && + !(r & O_NONBLOCK)) { + fptr->mode |= FMODE_WSPLIT; + } + fptr->mode |= FMODE_WSPLIT_INITIALIZED; + } + return fptr->mode & FMODE_WSPLIT; +} + /* writing functions */ static long io_fwrite(str, fptr) VALUE str; OpenFile *fptr; { - long len, n, r, offset = 0; + long len, n, r, l, offset = 0; FILE *f = GetWriteFile(fptr); len = RSTRING(str)->len; @@ -405,7 +424,14 @@ io_fwrite(str, fptr) rb_io_check_closed(fptr); } retry: - r = write(fileno(f), RSTRING(str)->ptr+offset, n); + l = n; + if (PIPE_BUF < l && + !rb_thread_critical && + !rb_thread_alone() && + wsplit_p(fptr)) { + l = PIPE_BUF; + } + r = write(fileno(f), RSTRING(str)->ptr+offset, l); if (r == n) return len; if (0 <= r) { offset += r; @@ -39,6 +39,8 @@ typedef struct OpenFile { #define FMODE_SYNC 8 #define FMODE_WBUF 16 #define FMODE_RBUF 32 +#define FMODE_WSPLIT 0x200 +#define FMODE_WSPLIT_INITIALIZED 0x400 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) |