Browse Source

ref isolate loop

v0.7.4-release
Igor Zinkovsky 13 years ago
parent
commit
de78922b12
  1. 3
      src/node.cc
  2. 2
      src/node.js
  3. 15
      src/node_isolate.cc
  4. 1
      src/node_isolate.h
  5. 1
      test/simple/test-isolates0.js

3
src/node.cc

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

2
src/node.js

@ -135,6 +135,8 @@
msg = JSON.parse('' + msg);
process.emit('message', msg);
};
process.exit = process._exit;
}
startup.globalVariables = function() {

15
src/node_isolate.cc

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

1
src/node_isolate.h

@ -74,6 +74,7 @@ public:
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());

1
test/simple/test-isolates0.js

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

Loading…
Cancel
Save