isolates: isolate-ify the main loop

pull/5370/head
Ben Noordhuis 2011-11-22 17:10:09 +01:00
parent e9f8e28426
commit 356992fe4d
17 changed files with 198 additions and 75 deletions

View File

@ -74,6 +74,7 @@
'src/node.cc',
'src/node_vars.cc',
'src/node_buffer.cc',
'src/node_isolate.cc',
'src/node_constants.cc',
'src/node_extensions.cc',
'src/node_file.cc',
@ -97,6 +98,7 @@
'src/node.h',
'src/node_vars.h',
'src/node_buffer.h',
'src/node_isolate.h',
'src/node_constants.h',
'src/node_crypto.h',
'src/node_extensions.h',

View File

@ -607,7 +607,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
if (status) {
// Error
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = Local<Value>::New(Null());
} else {
// Success
@ -710,7 +710,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
hints.ai_family = fam;
hints.ai_socktype = SOCK_STREAM;
int r = uv_getaddrinfo(uv_default_loop(),
int r = uv_getaddrinfo(NODE_LOOP(),
&req_wrap->req_,
AfterGetAddrInfo,
*hostname,
@ -719,7 +719,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
req_wrap->Dispatched();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
@ -736,7 +736,7 @@ static void Initialize(Handle<Object> target) {
assert(r == ARES_SUCCESS);
struct ares_options options;
uv_ares_init_options(uv_default_loop(), &ares_channel, &options, 0);
uv_ares_init_options(NODE_LOOP(), &ares_channel, &options, 0);
assert(r == 0);
NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>);

View File

@ -109,15 +109,15 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
String::Utf8Value path(args[0]->ToString());
int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
int r = uv_fs_event_init(NODE_LOOP(), &wrap->handle_, *path, OnEvent, 0);
if (r == 0) {
// Check for persistent argument
if (!args[1]->IsTrue()) {
uv_unref(uv_default_loop());
uv_unref(NODE_LOOP());
}
wrap->initialized_ = true;
} else {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
return scope.Close(Integer::New(r));
@ -145,7 +145,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
// assumption that a rename implicitly means an attribute change. Not too
// unreasonable, right? Still, we should revisit this before v1.0.
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
eventStr = String::Empty();
}
else if (events & UV_RENAME) {

View File

@ -70,7 +70,7 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {
}
wrap->unref = true;
uv_unref(uv_default_loop());
uv_unref(NODE_LOOP());
return v8::Undefined();
}
@ -102,7 +102,6 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
assert(!wrap->object_.IsEmpty());
uv_close(wrap->handle__, OnClose);
HandleWrap::Ref(args);
wrap->StateChange();

View File

@ -170,7 +170,7 @@ static void Idle(uv_idle_t* watcher, int status) {
static void Check(uv_check_t* watcher, int status) {
assert(watcher == &gc_check);
tick_times[tick_time_head] = uv_now(uv_default_loop());
tick_times[tick_time_head] = uv_now(NODE_LOOP());
tick_time_head = (tick_time_head + 1) % RPM_SAMPLES;
StartGCTimer();
@ -200,7 +200,7 @@ static void Tick(void) {
need_tick_cb = false;
if (uv_is_active((uv_handle_t*) &tick_spinner)) {
uv_idle_stop(&tick_spinner);
uv_unref(uv_default_loop());
uv_unref(NODE_LOOP());
}
HandleScope scope;
@ -242,7 +242,7 @@ static Handle<Value> NeedTickCallback(const Arguments& args) {
// 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_ref(NODE_LOOP());
}
return Undefined();
}
@ -1494,7 +1494,7 @@ static void CheckStatus(uv_timer_t* watcher, int status) {
}
}
double d = uv_now(uv_default_loop()) - TICK_TIME(3);
double d = uv_now(NODE_LOOP()) - TICK_TIME(3);
//printfb("timer d = %f\n", d);
@ -1523,7 +1523,7 @@ static Handle<Value> Uptime(const Arguments& args) {
v8::Handle<v8::Value> UVCounters(const v8::Arguments& args) {
HandleScope scope;
uv_counters_t* c = &uv_default_loop()->counters;
uv_counters_t* c = &NODE_LOOP()->counters;
Local<Object> obj = Object::New();
@ -2566,26 +2566,29 @@ char** Init(int argc, char *argv[]) {
RegisterSignalHandler(SIGTERM, SignalExit);
#endif // __POSIX__
// Don't use NODE_LOOP(), the node::Isolate() has not yet been initialized.
uv_loop_t* const loop = uv_default_loop();
uv_prepare_init(uv_default_loop(), &prepare_tick_watcher);
uv_prepare_start(&prepare_tick_watcher, PrepareTick);
uv_unref(uv_default_loop());
uv_unref(loop);
uv_check_init(uv_default_loop(), &check_tick_watcher);
uv_check_start(&check_tick_watcher, node::CheckTick);
uv_unref(uv_default_loop());
uv_unref(loop);
uv_idle_init(uv_default_loop(), &tick_spinner);
uv_unref(uv_default_loop());
uv_unref(loop);
uv_check_init(uv_default_loop(), &gc_check);
uv_check_start(&gc_check, node::Check);
uv_unref(uv_default_loop());
uv_unref(loop);
uv_idle_init(uv_default_loop(), &gc_idle);
uv_unref(uv_default_loop());
uv_unref(loop);
uv_timer_init(uv_default_loop(), &gc_timer);
uv_unref(uv_default_loop());
uv_unref(loop);
V8::SetFatalErrorHandler(node::OnFatalError);
@ -2598,13 +2601,13 @@ char** Init(int argc, char *argv[]) {
// main thread to execute a random bit of javascript - which will give V8
// control so it can handle whatever new message had been received on the
// debug thread.
uv_async_init(uv_default_loop(), &debug_watcher, node::DebugMessageCallback);
uv_async_init(loop, &debug_watcher, node::DebugMessageCallback);
// unref it so that we exit the event loop despite it being active.
uv_unref(uv_default_loop());
uv_unref(loop);
// Fetch a reference to the main isolate, so we have a reference to it
// even when we need it to access it from another (debugger) thread.
node_isolate = Isolate::GetCurrent();
node_isolate = v8::Isolate::GetCurrent();
// If the --debug flag was specified then initialize the debug thread.
if (use_debug_agent) {
@ -2646,7 +2649,11 @@ int Start(int argc, char *argv[]) {
Persistent<v8::Context> context = v8::Context::New();
v8::Context::Scope context_scope(context);
// Create the main node::Isolate object
Isolate::New(uv_default_loop());
Handle<Object> process_l = SetupProcessObject(argc, argv);
v8_typed_array::AttachBindings(context->Global());
// Create all the objects, load modules, do everything.
@ -2658,7 +2665,7 @@ int Start(int argc, char *argv[]) {
// there are no watchers on the loop (except for the ones that were
// uv_unref'd) then this function exits. As long as there are active
// watchers, it blocks.
uv_run(uv_default_loop());
uv_run(NODE_LOOP());
EmitExit(process_l);

View File

@ -64,6 +64,7 @@
#include <sys/stat.h>
#include <assert.h>
#include <node_isolate.h>
#include <node_object_wrap.h>
#ifndef offset_of
@ -87,6 +88,8 @@
#define NODE_STRINGIFY_HELPER(n) #n
#endif
#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop())
namespace node {
int Start(int argc, char *argv[]);

View File

@ -4117,7 +4117,8 @@ PBKDF2(const Arguments& args) {
req = new uv_work_t();
req->data = request;
uv_queue_work(uv_default_loop(), req, EIO_PBKDF2, EIO_PBKDF2After);
uv_queue_work(NODE_LOOP(), req, EIO_PBKDF2, EIO_PBKDF2After);
return Undefined();
err:
@ -4239,7 +4240,7 @@ Handle<Value> RandomBytes(const Arguments& args) {
Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
req->callback_ = Persistent<Function>::New(callback_v);
uv_queue_work(uv_default_loop(),
uv_queue_work(NODE_LOOP(),
&req->work_req_,
RandomBytesWork<generator>,
RandomBytesAfter<generator>);

View File

@ -0,0 +1,42 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_isolate.h"
#include <assert.h>
namespace node {
Isolate* Isolate::New(uv_loop_t* loop) {
return new Isolate(loop);
}
Isolate::Isolate(uv_loop_t* loop) {
loop_ = loop;
isolate_ = v8::Isolate::GetCurrent();
assert(isolate_->GetData() == NULL);
isolate_->SetData(this);
}
} // namespace node

69
src/node_isolate.h 100644
View File

@ -0,0 +1,69 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_NODE_ISOLATE_H_
#define SRC_NODE_ISOLATE_H_
#include <v8.h>
#include <uv.h>
#ifdef NDEBUG
# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr))
#else
# include <assert.h>
# define NODE_ISOLATE_CHECK(ptr) \
do { \
node::Isolate* data_ = node::Isolate::GetCurrent(); \
assert(data_ == (ptr)); \
} \
while (0)
#endif
namespace node {
class Isolate {
public:
static Isolate* New(uv_loop_t* loop);
static Isolate* GetCurrent() {
return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
}
uv_loop_t* GetLoop() {
NODE_ISOLATE_CHECK(this);
return loop_;
}
operator v8::Isolate*() {
NODE_ISOLATE_CHECK(this);
return isolate_;
}
private:
Isolate(uv_loop_t* loop);
v8::Isolate* isolate_;
uv_loop_t* loop_;
};
} // namespace node
#endif // SRC_NODE_ISOLATE_H_

View File

@ -133,7 +133,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
uv_work_t* work_req = new uv_work_t();
work_req->data = req_wrap;
uv_queue_work(uv_default_loop(),
uv_queue_work(NODE_LOOP(),
work_req,
ZCtx<mode>::Process,
ZCtx<mode>::After);

View File

@ -123,7 +123,7 @@ Handle<Value> PipeWrap::New(const Arguments& args) {
PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
: StreamWrap(object, (uv_stream_t*) &handle_) {
int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
int r = uv_pipe_init(NODE_LOOP(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
handle_.data = reinterpret_cast<void*>(this);
@ -141,7 +141,7 @@ Handle<Value> PipeWrap::Bind(const Arguments& args) {
int r = uv_pipe_bind(&wrap->handle_, *name);
// Error starting the pipe.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -172,7 +172,7 @@ Handle<Value> PipeWrap::Listen(const Arguments& args) {
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the pipe.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -225,7 +225,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
assert(wrap->object_.IsEmpty() == false);
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {

View File

@ -175,7 +175,7 @@ class ProcessWrap : public HandleWrap {
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif
int r = uv_spawn(uv_default_loop(), &wrap->process_, options);
int r = uv_spawn(NODE_LOOP(), &wrap->process_, options);
wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);
@ -195,7 +195,7 @@ class ProcessWrap : public HandleWrap {
delete [] options.env;
}
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -209,7 +209,7 @@ class ProcessWrap : public HandleWrap {
int r = uv_process_kill(&wrap->process_, signal);
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}

View File

@ -132,7 +132,7 @@ Handle<Value> StreamWrap::ReadStart(const Arguments& args) {
}
// Error starting the tcp.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -146,7 +146,7 @@ Handle<Value> StreamWrap::ReadStop(const Arguments& args) {
int r = uv_read_stop(wrap->stream_);
// Error starting the tcp.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -225,7 +225,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
slab_used -= buf.len;
}
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
MakeCallback(wrap->object_, "onread", 0, NULL);
return;
}
@ -338,7 +338,7 @@ Handle<Value> StreamWrap::Write(const Arguments& args) {
wrap->UpdateWriteQueueSize();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
@ -358,7 +358,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
assert(wrap->object_.IsEmpty() == false);
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
wrap->UpdateWriteQueueSize();
@ -388,7 +388,7 @@ Handle<Value> StreamWrap::Shutdown(const Arguments& args) {
req_wrap->Dispatched();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
@ -408,7 +408,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
HandleScope scope;
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {

View File

@ -154,7 +154,7 @@ Handle<Value> TCPWrap::New(const Arguments& args) {
TCPWrap::TCPWrap(Handle<Object> object)
: StreamWrap(object, (uv_stream_t*) &handle_) {
int r = uv_tcp_init(uv_default_loop(), &handle_);
int r = uv_tcp_init(NODE_LOOP(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void.
UpdateWriteQueueSize();
@ -182,7 +182,7 @@ Handle<Value> TCPWrap::GetSockName(const Arguments& args) {
Local<Object> sockname = Object::New();
if (r != 0) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
} else {
family = address.ss_family;
@ -224,7 +224,7 @@ Handle<Value> TCPWrap::GetPeerName(const Arguments& args) {
Local<Object> sockname = Object::New();
if (r != 0) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
} else {
family = address.ss_family;
@ -257,7 +257,7 @@ Handle<Value> TCPWrap::SetNoDelay(const Arguments& args) {
int r = uv_tcp_nodelay(&wrap->handle_, 1);
if (r)
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
@ -273,7 +273,7 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
if (r)
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
@ -289,7 +289,7 @@ Handle<Value> TCPWrap::SetSimultaneousAccepts(const Arguments& args) {
int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0);
if (r)
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
@ -308,7 +308,7 @@ Handle<Value> TCPWrap::Bind(const Arguments& args) {
int r = uv_tcp_bind(&wrap->handle_, address);
// Error starting the tcp.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -326,7 +326,7 @@ Handle<Value> TCPWrap::Bind6(const Arguments& args) {
int r = uv_tcp_bind6(&wrap->handle_, address);
// Error starting the tcp.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -342,7 +342,7 @@ Handle<Value> TCPWrap::Listen(const Arguments& args) {
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the tcp.
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -377,7 +377,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
// Successful accept. Call the onconnection callback in JavaScript land.
argv[0] = client_obj;
} else {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = v8::Null();
}
@ -396,7 +396,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
assert(wrap->object_.IsEmpty() == false);
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {
@ -432,7 +432,7 @@ Handle<Value> TCPWrap::Connect(const Arguments& args) {
req_wrap->Dispatched();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
@ -459,7 +459,7 @@ Handle<Value> TCPWrap::Connect6(const Arguments& args) {
req_wrap->Dispatched();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {

View File

@ -91,7 +91,7 @@ class TimerWrap : public HandleWrap {
: HandleWrap(object, (uv_handle_t*) &handle_) {
active_ = false;
int r = uv_timer_init(uv_default_loop(), &handle_);
int r = uv_timer_init(NODE_LOOP(), &handle_);
assert(r == 0);
handle_.data = this;
@ -99,11 +99,11 @@ class TimerWrap : public HandleWrap {
// 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());
uv_unref(NODE_LOOP());
}
~TimerWrap() {
if (!active_) uv_ref(uv_default_loop());
if (!active_) uv_ref(NODE_LOOP());
}
void StateChange() {
@ -113,11 +113,11 @@ class TimerWrap : public HandleWrap {
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());
uv_ref(NODE_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());
uv_unref(NODE_LOOP());
}
}
@ -132,7 +132,7 @@ 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()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
@ -146,7 +146,7 @@ class TimerWrap : public HandleWrap {
int r = uv_timer_stop(&wrap->handle_);
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
@ -160,7 +160,7 @@ class TimerWrap : public HandleWrap {
int r = uv_timer_again(&wrap->handle_);
if (r) SetErrno(uv_last_error(uv_default_loop()));
if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
@ -186,7 +186,7 @@ class TimerWrap : public HandleWrap {
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
if (repeat < 0) SetErrno(uv_last_error(uv_default_loop()));
if (repeat < 0) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(repeat));
}

View File

@ -124,7 +124,7 @@ class TTYWrap : StreamWrap {
int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return v8::Undefined();
}
@ -143,7 +143,7 @@ class TTYWrap : StreamWrap {
int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
return scope.Close(Integer::New(r));
@ -169,7 +169,7 @@ class TTYWrap : StreamWrap {
TTYWrap(Handle<Object> object, int fd, bool readable)
: StreamWrap(object, (uv_stream_t*)&handle_) {
uv_tty_init(uv_default_loop(), &handle_, fd, readable);
uv_tty_init(NODE_LOOP(), &handle_, fd, readable);
}
uv_tty_t handle_;

View File

@ -103,7 +103,7 @@ private:
UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) {
int r = uv_udp_init(uv_default_loop(), &handle_);
int r = uv_udp_init(NODE_LOOP(), &handle_);
assert(r == 0); // can't fail anyway
handle_.data = reinterpret_cast<void*>(this);
}
@ -176,7 +176,7 @@ Handle<Value> UDPWrap::DoBind(const Arguments& args, int family) {
}
if (r)
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
@ -233,7 +233,7 @@ Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
req_wrap->Dispatched();
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return Null();
}
@ -260,8 +260,8 @@ Handle<Value> UDPWrap::RecvStart(const Arguments& args) {
// UV_EALREADY means that the socket is already bound but that's okay
int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) {
SetErrno(uv_last_error(uv_default_loop()));
if (r && uv_last_error(NODE_LOOP()).code != UV_EALREADY) {
SetErrno(uv_last_error(NODE_LOOP()));
return False();
}
@ -297,7 +297,7 @@ Handle<Value> UDPWrap::GetSockName(const Arguments& args) {
return scope.Close(sockname);
}
else {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
return Null();
}
}
@ -316,7 +316,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
assert(wrap->object_.IsEmpty() == false);
if (status) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[4] = {
@ -364,7 +364,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
};
if (nread == -1) {
SetErrno(uv_last_error(uv_default_loop()));
SetErrno(uv_last_error(NODE_LOOP()));
}
else {
Local<Object> rinfo = Object::New();