Move uv loop initialization into isolate
authorRyan Dahl <ry@tinyclouds.org>
Tue, 13 Dec 2011 22:48:36 +0000 (14:48 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 27 Dec 2011 20:54:23 +0000 (12:54 -0800)
src/node.cc
src/node_isolate.cc
src/node_isolate.h

index 194a6de..86b9121 100644 (file)
@@ -1891,8 +1891,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;
@@ -2780,7 +2779,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();
 
index adaa4b2..138e29e 100644 (file)
@@ -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) {
index 5529da2..8557ffa 100644 (file)
@@ -48,7 +48,7 @@ public:
 
   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());
@@ -82,7 +82,7 @@ public:
   unsigned int id_;
 
 private:
-  Isolate(uv_loop_t* loop);
+  Isolate();
 
   struct AtExitCallbackInfo {
     ngx_queue_t at_exit_callbacks_;