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

Commit

Permalink
ref isolate loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Jan 21, 2012
1 parent f9a47de commit de78922
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/node.cc
Expand Up @@ -2649,6 +2649,9 @@ void StartThread(node::Isolate* isolate,
if (isolate->id_ > 1) {
process_l->Set(String::NewSymbol("_send"),
FunctionTemplate::New(Isolate::Send)->GetFunction());

process_l->Set(String::NewSymbol("_exit"),
FunctionTemplate::New(Isolate::Unref)->GetFunction());
}

// FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed"
Expand Down
2 changes: 2 additions & 0 deletions src/node.js
Expand Up @@ -135,6 +135,8 @@
msg = JSON.parse('' + msg);
process.emit('message', msg);
};

process.exit = process._exit;
}

startup.globalVariables = function() {
Expand Down
15 changes: 15 additions & 0 deletions src/node_isolate.cc
Expand Up @@ -215,6 +215,16 @@ Handle<Value> Isolate::Send(const Arguments& args) {
}


Handle<Value> Isolate::Unref(const Arguments& args) {
HandleScope scope;

Isolate* isolate = Isolate::GetCurrent();
uv_unref(isolate->loop_);

return Undefined();
}


void Isolate::OnMessage(IsolateMessage* msg, void* arg) {
HandleScope scope;

Expand Down Expand Up @@ -270,6 +280,11 @@ Isolate::Isolate() {
assert(v8_isolate_->GetData() == NULL);
v8_isolate_->SetData(this);

// Artificially ref the isolate loop so that the child
// isolate stays alive by default. process.exit will
// unref the loop (see Isolate::Unref).
uv_ref(loop_);

globals_init_ = false;
}

Expand Down
1 change: 1 addition & 0 deletions src/node_isolate.h
Expand Up @@ -74,6 +74,7 @@ class Isolate {
typedef void (*AtExitCallback)(void* arg);

static v8::Handle<v8::Value> Send(const v8::Arguments& args);
static v8::Handle<v8::Value> Unref(const v8::Arguments& args);

static Isolate* GetCurrent() {
return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-isolates0.js
Expand Up @@ -52,6 +52,7 @@ if (process.tid === 1) {
fs.stat(__dirname, function(err, stat) {
if (err) throw err;
console.error('thread 2', stat.mtime);
process.exit();
});
}, 500);

Expand Down

0 comments on commit de78922

Please sign in to comment.