mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 15:06:33 +01:00
enable support for the thread pool
This commit is contained in:
parent
1a126ed11c
commit
0e9e927fcb
32
src/node.cc
32
src/node.cc
@ -1,6 +1,4 @@
|
||||
#include "node.h"
|
||||
#define EV_STANDALONE 1
|
||||
#include <ev.c>
|
||||
|
||||
#include "node_tcp.h"
|
||||
#include "node_http.h"
|
||||
@ -189,6 +187,28 @@ v8::Handle<v8::Value> 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<v8::String> 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);
|
||||
|
@ -1,13 +1,15 @@
|
||||
#ifndef node_h
|
||||
#define node_h
|
||||
|
||||
#define EV_STANDALONE 1
|
||||
#include <ev.h>
|
||||
|
||||
#include <eio.h>
|
||||
#include <v8.h>
|
||||
|
||||
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
|
||||
|
||||
|
4
wscript
4
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"
|
||||
|
Loading…
Reference in New Issue
Block a user