src: use new loop API
authorSaúl Ibarra Corretgé <saghul@gmail.com>
Fri, 28 Feb 2014 09:17:32 +0000 (10:17 +0100)
committerFedor Indutny <fedor.indutny@gmail.com>
Fri, 28 Feb 2014 10:01:52 +0000 (14:01 +0400)
uv_loop_new and uv_loop_delete are considered deprecated now.

src/node_watchdog.cc
src/spawn_sync.cc

index cec9aa5..dd62dd7 100644 (file)
@@ -29,10 +29,13 @@ using v8::V8;
 
 
 Watchdog::Watchdog(uint64_t ms) : destroyed_(false) {
-  loop_ = uv_loop_new();
+  int rc;
+  loop_ = new uv_loop_t;
   CHECK(loop_);
+  rc = uv_loop_init(loop_);
+  CHECK_EQ(0, rc);
 
-  int rc = uv_async_init(loop_, &async_, &Watchdog::Async);
+  rc = uv_async_init(loop_, &async_, &Watchdog::Async);
   CHECK_EQ(0, rc);
 
   rc = uv_timer_init(loop_, &timer_);
@@ -69,7 +72,10 @@ void Watchdog::Destroy() {
   // UV_RUN_DEFAULT so that libuv has a chance to clean up.
   uv_run(loop_, UV_RUN_DEFAULT);
 
-  uv_loop_delete(loop_);
+  int rc = uv_loop_close(loop_);
+  CHECK_EQ(0, rc);
+  delete loop_;
+  loop_ = NULL;
 
   destroyed_ = true;
 }
index 4876422..9b67a60 100644 (file)
@@ -22,6 +22,7 @@
 #include "spawn_sync.h"
 #include "env-inl.h"
 #include "string_bytes.h"
+#include "util.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -450,9 +451,10 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
   assert(lifecycle_ == kUninitialized);
   lifecycle_ = kInitialized;
 
-  uv_loop_ = uv_loop_new();
+  uv_loop_ = new uv_loop_t;
   if (uv_loop_ == NULL)
     return SetError(UV_ENOMEM);
+  CHECK_EQ(uv_loop_init(uv_loop_), 0);
 
   r = ParseOptions(options);
   if (r < 0)
@@ -515,7 +517,9 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
     if (r < 0)
       abort();
 
-    uv_loop_delete(uv_loop_);
+    CHECK_EQ(uv_loop_close(uv_loop_), 0);
+    delete uv_loop_;
+    uv_loop_ = NULL;
 
   } else {
     // If the loop doesn't exist, neither should any pipes or timers.