From 5207226da36c73a72e69e701bfcea2b1907d6eae Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 18 Apr 2009 02:01:23 +0200 Subject: [PATCH] fix a bug with eio polling. --- src/file.cc | 13 +++++++------ src/file.js | 3 +++ src/node.cc | 14 ++++++++++++-- src/node.h | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/file.cc b/src/file.cc index 832c63e..3baf676 100644 --- a/src/file.cc +++ b/src/file.cc @@ -103,8 +103,8 @@ FileSystem::Rename (const Arguments& args) String::Utf8Value path(args[0]->ToString()); String::Utf8Value new_path(args[1]->ToString()); + node_eio_warmup(); eio_req *req = eio_rename(*path, *new_path, EIO_PRI_DEFAULT, AfterRename, NULL); - node_eio_submit(req); return Undefined(); } @@ -130,8 +130,8 @@ FileSystem::Stat (const Arguments& args) String::Utf8Value path(args[0]->ToString()); + node_eio_warmup(); eio_req *req = eio_stat(*path, EIO_PRI_DEFAULT, AfterStat, NULL); - node_eio_submit(req); return Undefined(); } @@ -245,8 +245,8 @@ File::Close (const Arguments& args) int fd = file->GetFD(); + node_eio_warmup(); eio_req *req = eio_close (fd, EIO_PRI_DEFAULT, File::AfterClose, file); - node_eio_submit(req); return Undefined(); } @@ -306,8 +306,8 @@ File::Open (const Arguments& args) } // TODO how should the mode be set? + node_eio_warmup(); eio_req *req = eio_open (*path, flags, 0666, EIO_PRI_DEFAULT, File::AfterOpen, file); - node_eio_submit(req); return Undefined(); } @@ -373,8 +373,8 @@ File::Write (const Arguments& args) int fd = file->GetFD(); // NOTE: -1 offset in eio_write() invokes write() instead of pwrite() + node_eio_warmup(); eio_req *req = eio_write(fd, buf, length, -1, EIO_PRI_DEFAULT, File::AfterWrite, file); - node_eio_submit(req); return Undefined(); } @@ -413,8 +413,9 @@ File::Read (const Arguments& args) // NOTE: -1 offset in eio_read() invokes read() instead of pread() // NULL pointer tells eio to allocate it itself + node_eio_warmup(); eio_req *req = eio_read(fd, NULL, length, -1, EIO_PRI_DEFAULT, File::AfterRead, file); - node_eio_submit(req); + assert(req); return Undefined(); } diff --git a/src/file.js b/src/file.js index 513bd75..1c89ee6 100644 --- a/src/file.js +++ b/src/file.js @@ -77,3 +77,6 @@ stderr.fd = File.STDERR_FILENO; var stdin = new File(); stdin.fd = File.STDIN_FILENO; +this.puts = function (data, callback) { + stdout.puts(data, callback); +} diff --git a/src/node.cc b/src/node.cc index 25a855e..700a552 100644 --- a/src/node.cc +++ b/src/node.cc @@ -181,7 +181,12 @@ thread_pool_cb (EV_P_ ev_async *w, int revents) { int r = eio_poll(); /* returns 0 if all requests were handled, -1 if not, or the value of EIO_FINISH if != 0 */ - if(r == 0) ev_async_stop(EV_DEFAULT_ w); + + // XXX is this check too heavy? + // it require three locks in eio + // what's the better way? + if (eio_nreqs () == 0 && eio_nready() == 0 && eio_npending() == 0) + ev_async_stop(EV_DEFAULT_ w); } static void @@ -190,8 +195,13 @@ thread_pool_want_poll (void) ev_async_send(EV_DEFAULT_ &thread_pool_watcher); } +static void +thread_pool_done_poll (void) +{ +} + void -node_eio_submit(eio_req *req) +node_eio_warmup (void) { ev_async_start(EV_DEFAULT_ &thread_pool_watcher); } diff --git a/src/node.h b/src/node.h index 28968ea..eabf7bd 100644 --- a/src/node.h +++ b/src/node.h @@ -17,7 +17,7 @@ void node_fatal_exception (v8::TryCatch &try_catch); void node_exit (int code); // call this after creating a new eio event. -void node_eio_submit(eio_req *req); +void node_eio_warmup (void); #endif // node_h -- 2.7.4