src: initialize debug-related uv_async_t handles

uv_async_t handles for dispatching of debug messages and
emitting NODE_DEBUG_ENABLED used to be initialized every time
node::EnableDebug() was called, which happened every time
user sends a SIGUSR1.

Now they are initialized only once from node::Init() during
application start.
pull/5010/head
Miroslav Bajtoš 2013-05-02 16:42:49 +02:00 committed by Ben Noordhuis
parent 43ec1b1c2e
commit fbf4641462
1 changed files with 14 additions and 11 deletions

View File

@ -2746,12 +2746,8 @@ static void EmitDebugEnabledAsyncCallback(uv_async_t* handle, int status) {
} }
// Called from the signal handler (unix) or off-thread (windows) // Called from the signal watcher callback
static void EmitDebugEnabled() { static void EmitDebugEnabled() {
uv_async_init(uv_default_loop(),
&emit_debug_enabled_async,
EmitDebugEnabledAsyncCallback);
uv_unref((uv_handle_t*) &emit_debug_enabled_async);
uv_async_send(&emit_debug_enabled_async); uv_async_send(&emit_debug_enabled_async);
} }
@ -2764,11 +2760,6 @@ static void EnableDebug(bool wait_connect) {
v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback, v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback,
false); false);
uv_async_init(uv_default_loop(),
&dispatch_debug_messages_async,
DispatchDebugMessagesAsyncCallback);
uv_unref((uv_handle_t*) &dispatch_debug_messages_async);
// Start the debug thread and it's associated TCP server on port 5858. // Start the debug thread and it's associated TCP server on port 5858.
bool r = v8::Debug::EnableAgent("node " NODE_VERSION, bool r = v8::Debug::EnableAgent("node " NODE_VERSION,
debug_port, debug_port,
@ -2783,7 +2774,7 @@ static void EnableDebug(bool wait_connect) {
debugger_running = true; debugger_running = true;
// Do not emit _debug_enabled when debugger is enabled before starting // Do not emit NODE_DEBUG_ENABLED when debugger is enabled before starting
// the main process (i.e. when called via `node --debug`) // the main process (i.e. when called via `node --debug`)
if (!process.IsEmpty()) if (!process.IsEmpty())
EmitDebugEnabled(); EmitDebugEnabled();
@ -3016,6 +3007,18 @@ char** Init(int argc, char *argv[]) {
// Make inherited handles noninheritable. // Make inherited handles noninheritable.
uv_disable_stdio_inheritance(); uv_disable_stdio_inheritance();
// init async debug messages dispatching
uv_async_init(uv_default_loop(),
&dispatch_debug_messages_async,
DispatchDebugMessagesAsyncCallback);
uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async));
// init async NODE_DEBUG_ENABLED emitter
uv_async_init(uv_default_loop(),
&emit_debug_enabled_async,
EmitDebugEnabledAsyncCallback);
uv_unref(reinterpret_cast<uv_handle_t*>(&emit_debug_enabled_async));
// Parse a few arguments which are specific to Node. // Parse a few arguments which are specific to Node.
node::ParseArgs(argc, argv); node::ParseArgs(argc, argv);
// Parse the rest of the args (up to the 'option_end_index' (where '--' was // Parse the rest of the args (up to the 'option_end_index' (where '--' was