0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 07:00:59 +01:00

fix a bug with eio polling.

This commit is contained in:
Ryan 2009-04-18 02:01:23 +02:00
parent dd691decd2
commit 5207226da3
4 changed files with 23 additions and 9 deletions

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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