Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Move uv loop initialization into isolate
  • Loading branch information
ry committed Dec 14, 2011
1 parent 3197a20 commit 51e9fac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/node.cc
Expand Up @@ -1864,8 +1864,7 @@ struct ThreadInfo {
static void RunIsolate(void* arg) {
ThreadInfo* ti = reinterpret_cast<ThreadInfo*>(arg);

uv_loop_t* loop = uv_loop_new();
Isolate* isolate = Isolate::New(loop);
Isolate* isolate = Isolate::New();

StartThread(isolate, ti->argc_, ti->argv_);
delete ti;
Expand Down Expand Up @@ -2740,7 +2739,7 @@ int Start(int argc, char *argv[]) {

// Create the main node::Isolate object
node::Isolate::Initialize();
Isolate* isolate = node::Isolate::New(uv_default_loop());
Isolate* isolate = node::Isolate::New();
StartThread(isolate, argc, argv);
isolate->Dispose();

Expand Down
14 changes: 10 additions & 4 deletions src/node_isolate.cc
Expand Up @@ -40,20 +40,26 @@ void Isolate::Initialize() {
}
}

Isolate* Isolate::New(uv_loop_t* loop) {
return new Isolate(loop);

Isolate* Isolate::New() {
return new Isolate();
}


Isolate::Isolate(uv_loop_t* loop) {
Isolate::Isolate() {
assert(initialized && "node::Isolate::Initialize() hasn't been called");

uv_mutex_lock(&id_lock);
id_ = ++id;
uv_mutex_unlock(&id_lock);

if (id_ == 1) {
loop_ = uv_default_loop();
} else {
loop_ = uv_loop_new();
}

ngx_queue_init(&at_exit_callbacks_);
loop_ = loop;

v8_isolate_ = v8::Isolate::GetCurrent();
if (v8_isolate_ == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions src/node_isolate.h
Expand Up @@ -48,7 +48,7 @@ class Isolate {

typedef void (*AtExitCallback)(void* arg);

static Isolate* New(uv_loop_t* loop);
static Isolate* New();

static Isolate* GetCurrent() {
return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
Expand Down Expand Up @@ -82,7 +82,7 @@ class Isolate {
unsigned int id_;

private:
Isolate(uv_loop_t* loop);
Isolate();

struct AtExitCallbackInfo {
ngx_queue_t at_exit_callbacks_;
Expand Down

0 comments on commit 51e9fac

Please sign in to comment.