diff --git a/src/node.cc b/src/node.cc index ad7b2f88396..e89b88c042b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1,6 +1,4 @@ #include "node.h" -#define EV_STANDALONE 1 -#include #include "node_tcp.h" #include "node_http.h" @@ -189,6 +187,28 @@ v8::Handle Load(const v8::Arguments& args) { return v8::Undefined(); } +static ev_async thread_pool_watcher; + +static void +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); +} + +static void +thread_pool_want_poll (void) +{ + ev_async_send(EV_DEFAULT_ &thread_pool_watcher); +} + +void +node_eio_submit(eio_req *req) +{ + ev_async_start(EV_DEFAULT_ &thread_pool_watcher); +} + int main (int argc, char *argv[]) { @@ -198,6 +218,8 @@ main (int argc, char *argv[]) fprintf(stderr, "No script was specified.\n"); return 1; } + + string filename(argv[1]); HandleScope handle_scope; @@ -226,6 +248,12 @@ main (int argc, char *argv[]) V8::SetFatalErrorHandler(OnFatalError); v8::Handle source = ReadFile(filename); + + // start eio thread pool + ev_async_init(&thread_pool_watcher, thread_pool_cb); + ev_async_start(EV_DEFAULT_ &thread_pool_watcher); + eio_init(thread_pool_want_poll, NULL); + ExecuteString(source, String::New(filename.c_str()), false, true); ev_loop(node_loop(), 0); diff --git a/src/node.h b/src/node.h index 91ed676459f..3d075a9abd3 100644 --- a/src/node.h +++ b/src/node.h @@ -1,13 +1,15 @@ #ifndef node_h #define node_h -#define EV_STANDALONE 1 #include - +#include #include void node_fatal_exception (v8::TryCatch &try_catch); #define node_loop() ev_default_loop(0) +// call this after creating a new eio event. +void node_eio_submit(eio_req *req); + #endif // node_h diff --git a/wscript b/wscript index ade7f3f7b48..361ecffe069 100644 --- a/wscript +++ b/wscript @@ -42,9 +42,7 @@ def configure(conf): conf.define("HAVE_CONFIG_H", 1) conf.write_config_header('config.h') - def build(bld): - bld.add_subdirs('deps/libeio deps/libev') ### v8 @@ -100,4 +98,4 @@ def build(bld): deps/ebb """ node.uselib_local = "oi ev eio ebb" - node.uselib = "V8 PTHREAD" + node.uselib = "V8"