diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-05-17 07:13:29 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-05-22 16:14:24 +0200 |
commit | 039fac633eaf081a96bb1ed8bc7307d03dcbe9d9 (patch) | |
tree | b24085e8aab84e09ed8fd7d311cd360dbfd6259e /src | |
parent | a608f65b2454a83f08a60ba24088a672097540f5 (diff) | |
download | android-node-v8-039fac633eaf081a96bb1ed8bc7307d03dcbe9d9.tar.gz android-node-v8-039fac633eaf081a96bb1ed8bc7307d03dcbe9d9.tar.bz2 android-node-v8-039fac633eaf081a96bb1ed8bc7307d03dcbe9d9.zip |
deps: upgrade libuv to a478847
The event loop's reference counting scheme in this version of libuv has changed.
Update the libuv bindings to reflect that fact.
Diffstat (limited to 'src')
-rw-r--r-- | src/fs_event_wrap.cc | 2 | ||||
-rw-r--r-- | src/handle_wrap.cc | 38 | ||||
-rw-r--r-- | src/handle_wrap.h | 4 | ||||
-rw-r--r-- | src/node.cc | 80 | ||||
-rw-r--r-- | src/pipe_wrap.cc | 1 | ||||
-rw-r--r-- | src/stream_wrap.h | 1 | ||||
-rw-r--r-- | src/timer_wrap.cc | 37 | ||||
-rw-r--r-- | src/tty_wrap.cc | 1 |
8 files changed, 27 insertions, 137 deletions
diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index e77de8dfd5..adac00c9fc 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -103,7 +103,7 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) { if (r == 0) { // Check for persistent argument if (!args[1]->IsTrue()) { - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->handle_)); } wrap->initialized_ = true; } else { diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index ba09e20da8..944631a3be 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -57,31 +57,8 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { UNWRAP(HandleWrap) - // Calling unnecessarily is a no-op - if (wrap->unref) { - return v8::Undefined(); - } - - wrap->unref = true; - uv_unref(uv_default_loop()); - - return v8::Undefined(); -} - - -// Adds a reference to keep uv alive because of this thing. -Handle<Value> HandleWrap::Ref(const Arguments& args) { - HandleScope scope; - - UNWRAP(HandleWrap) - - // Calling multiple times is a no-op - if (!wrap->unref) { - return v8::Undefined(); - } - - wrap->unref = false; - uv_ref(uv_default_loop()); + uv_unref(wrap->handle__); + wrap->unref_ = true; return v8::Undefined(); } @@ -93,16 +70,11 @@ Handle<Value> HandleWrap::Close(const Arguments& args) { HandleWrap *wrap = static_cast<HandleWrap*>( args.Holder()->GetPointerFromInternalField(0)); - if (wrap) { - // guard against uninitialized handle or double close - if (wrap->handle__ == NULL) return v8::Null(); + // guard against uninitialized handle or double close + if (wrap && wrap->handle__) { assert(!wrap->object_.IsEmpty()); uv_close(wrap->handle__, OnClose); wrap->handle__ = NULL; - - HandleWrap::Ref(args); - - wrap->StateChange(); } return v8::Null(); @@ -110,7 +82,7 @@ Handle<Value> HandleWrap::Close(const Arguments& args) { HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) { - unref = false; + unref_ = false; handle__ = h; if (h) { h->data = this; diff --git a/src/handle_wrap.h b/src/handle_wrap.h index c6dd4c9d6a..35853a0110 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -51,14 +51,12 @@ class HandleWrap { static void Initialize(v8::Handle<v8::Object> target); static v8::Handle<v8::Value> Close(const v8::Arguments& args); static v8::Handle<v8::Value> Unref(const v8::Arguments& args); - static v8::Handle<v8::Value> Ref(const v8::Arguments& args); protected: HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle); virtual ~HandleWrap(); virtual void SetHandle(uv_handle_t* h); - virtual void StateChange() {} v8::Persistent<v8::Object> object_; @@ -69,7 +67,7 @@ class HandleWrap { // Using double underscore due to handle_ member in tcp_wrap. Probably // tcp_wrap should rename it's member to 'handle'. uv_handle_t* handle__; - bool unref; + bool unref_; }; diff --git a/src/node.cc b/src/node.cc index d6cb9ae1e6..5db4d86c28 100644 --- a/src/node.cc +++ b/src/node.cc @@ -229,12 +229,9 @@ static void Check(uv_check_t* watcher, int status) { static void Tick(void) { // Avoid entering a V8 scope. if (!need_tick_cb) return; - need_tick_cb = false; - if (uv_is_active((uv_handle_t*) &tick_spinner)) { - uv_idle_stop(&tick_spinner); - uv_unref(uv_default_loop()); - } + + uv_idle_stop(&tick_spinner); HandleScope scope; @@ -270,10 +267,7 @@ static void StartTickSpinner() { // there is nothing left to do in the event loop and libev will exit. The // ev_prepare callback isn't called before exiting. Thus we start this // tick_spinner to keep the event loop alive long enough to handle it. - if (!uv_is_active((uv_handle_t*) &tick_spinner)) { - uv_idle_start(&tick_spinner, Spin); - uv_ref(uv_default_loop()); - } + uv_idle_start(&tick_spinner, Spin); } static Handle<Value> NeedTickCallback(const Arguments& args) { @@ -825,20 +819,6 @@ static const char* get_uv_errno_message(int errorno) { } -static bool get_uv_dlerror_message(uv_lib_t lib, char* error_msg, int size) { - int r; - const char *msg; - if ((msg = uv_dlerror(lib)) == NULL) { - r = snprintf(error_msg, size, "%s", "Unable to load shared library "); - } else { - r = snprintf(error_msg, size, "%s", msg); - uv_dlerror_free(lib, msg); - } - // return bool if the error message be written correctly - return (0 < r && r < size); -} - - // hack alert! copy of ErrnoException, tuned for uv errors Local<Value> UVException(int errorno, const char *syscall, @@ -1365,7 +1345,7 @@ Handle<Value> GetActiveHandles(const Arguments& args) { ngx_queue_foreach(q, &handle_wrap_queue) { HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_); - if (w->object_.IsEmpty() || w->unref) continue; + if (w->object_.IsEmpty() || w->unref_) continue; Local<Value> obj = w->object_->Get(owner_sym); if (obj->IsUndefined()) obj = *w->object_; ary->Set(i++, obj); @@ -1726,7 +1706,6 @@ Handle<Value> DLOpen(const v8::Arguments& args) { char symbol[1024], *base, *pos; uv_lib_t lib; node_module_struct compat_mod; - uv_err_t err; int r; if (args.Length() < 2) { @@ -1738,22 +1717,13 @@ Handle<Value> DLOpen(const v8::Arguments& args) { String::Utf8Value filename(args[0]); // Cast Local<Object> target = args[1]->ToObject(); // Cast - err = uv_dlopen(*filename, &lib); - if (err.code != UV_OK) { - // Retrieve uv_dlerror() message and throw exception with it - char dlerror_msg[1024]; - if (!get_uv_dlerror_message(lib, dlerror_msg, sizeof dlerror_msg)) { - Local<Value> exception = Exception::Error( - String::New("Cannot retrieve an error message in process.dlopen")); - return ThrowException(exception); - } -#ifdef __POSIX__ - Local<Value> exception = Exception::Error(String::New(dlerror_msg)); -#else // Windows needs to add the filename into the error message - Local<Value> exception = Exception::Error( - String::Concat(String::New(dlerror_msg), args[0]->ToString())); + if (uv_dlopen(*filename, &lib)) { + Local<String> errmsg = String::New(uv_dlerror(&lib)); +#ifdef _WIN32 + // Windows needs to add the filename into the error message + errmsg = String::Concat(errmsg, args[0]->ToString()); #endif - return ThrowException(exception); + return ThrowException(Exception::Error(errmsg)); } String::Utf8Value path(args[0]); @@ -1791,26 +1761,17 @@ Handle<Value> DLOpen(const v8::Arguments& args) { // Get the init() function from the dynamically shared object. node_module_struct *mod; - err = uv_dlsym(lib, symbol, reinterpret_cast<void**>(&mod)); - - if (err.code != UV_OK) { + if (uv_dlsym(&lib, symbol, reinterpret_cast<void**>(&mod))) { /* Start Compatibility hack: Remove once everyone is using NODE_MODULE macro */ memset(&compat_mod, 0, sizeof compat_mod); mod = &compat_mod; mod->version = NODE_MODULE_VERSION; - err = uv_dlsym(lib, "init", reinterpret_cast<void**>(&mod->register_func)); - if (err.code != UV_OK) { - uv_dlclose(lib); - - const char* message; - if (err.code == UV_ENOENT) - message = "Module entry point not found."; - else - message = uv_strerror(err); - - return ThrowException(Exception::Error(String::New(message))); + if (uv_dlsym(&lib, "init", reinterpret_cast<void**>(&mod->register_func))) { + Local<String> errmsg = String::New(uv_dlerror(&lib)); + uv_dlclose(&lib); + return ThrowException(Exception::Error(errmsg)); } /* End Compatibility hack */ } @@ -2779,24 +2740,23 @@ char** Init(int argc, char *argv[]) { uv_prepare_init(uv_default_loop(), &prepare_tick_watcher); uv_prepare_start(&prepare_tick_watcher, PrepareTick); - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&prepare_tick_watcher)); uv_check_init(uv_default_loop(), &check_tick_watcher); uv_check_start(&check_tick_watcher, node::CheckTick); - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&check_tick_watcher)); uv_idle_init(uv_default_loop(), &tick_spinner); - uv_unref(uv_default_loop()); uv_check_init(uv_default_loop(), &gc_check); uv_check_start(&gc_check, node::Check); - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&gc_check)); uv_idle_init(uv_default_loop(), &gc_idle); - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&gc_idle)); uv_timer_init(uv_default_loop(), &gc_timer); - uv_unref(uv_default_loop()); + uv_unref(reinterpret_cast<uv_handle_t*>(&gc_timer)); V8::SetFatalErrorHandler(node::OnFatalError); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 39b21a6fab..2ae74ec23b 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -84,7 +84,6 @@ void PipeWrap::Initialize(Handle<Object> target) { NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); - NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 43702f3c93..c51083c09c 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -54,7 +54,6 @@ class StreamWrap : public HandleWrap { protected: StreamWrap(v8::Handle<v8::Object> object, uv_stream_t* stream); - virtual ~StreamWrap() { } virtual void SetHandle(uv_handle_t* h); void StateChange() { } void UpdateWriteQueueSize(); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index acc8b5a40c..4332a68ba1 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -80,36 +80,12 @@ class TimerWrap : public HandleWrap { TimerWrap(Handle<Object> object) : HandleWrap(object, (uv_handle_t*) &handle_) { - active_ = false; - int r = uv_timer_init(uv_default_loop(), &handle_); assert(r == 0); - handle_.data = this; - - // uv_timer_init adds a loop reference. (That is, it calls uv_ref.) This - // is not the behavior we want in Node. Timers should not increase the - // ref count of the loop except when active. - uv_unref(uv_default_loop()); } ~TimerWrap() { - if (!active_) uv_ref(uv_default_loop()); - } - - void StateChange() { - bool was_active = active_; - active_ = uv_is_active((uv_handle_t*) &handle_); - - if (!was_active && active_) { - // If our state is changing from inactive to active, we - // increase the loop's reference count. - uv_ref(uv_default_loop()); - } else if (was_active && !active_) { - // If our state is changing from active to inactive, we - // decrease the loop's reference count. - uv_unref(uv_default_loop()); - } } static Handle<Value> Start(const Arguments& args) { @@ -122,11 +98,8 @@ class TimerWrap : public HandleWrap { int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat); - // Error starting the timer. if (r) SetErrno(uv_last_error(uv_default_loop())); - wrap->StateChange(); - return scope.Close(Integer::New(r)); } @@ -139,8 +112,6 @@ class TimerWrap : public HandleWrap { if (r) SetErrno(uv_last_error(uv_default_loop())); - wrap->StateChange(); - return scope.Close(Integer::New(r)); } @@ -153,8 +124,6 @@ class TimerWrap : public HandleWrap { if (r) SetErrno(uv_last_error(uv_default_loop())); - wrap->StateChange(); - return scope.Close(Integer::New(r)); } @@ -188,17 +157,11 @@ class TimerWrap : public HandleWrap { TimerWrap* wrap = static_cast<TimerWrap*>(handle->data); assert(wrap); - wrap->StateChange(); - Local<Value> argv[1] = { Integer::New(status) }; MakeCallback(wrap->object_, ontimeout_sym, ARRAY_SIZE(argv), argv); } uv_timer_t handle_; - // This member is set false initially. When the timer is turned - // on uv_ref is called. When the timer is turned off uv_unref is - // called. Used to mirror libev semantics. - bool active_; }; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 1a9ec5600d..de43a4f23c 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -56,7 +56,6 @@ class TTYWrap : StreamWrap { NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); - NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); |