From 02de9c3b393da3ba2247464c1cc8a047a86c92e9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 29 Jul 2013 20:50:03 +0800 Subject: [PATCH] Enable idle GC for both browser and renderer. --- common/node_bindings.cc | 10 ++++++++++ common/node_bindings.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 2605d263e9b8..1676c5f7b0ec 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -42,6 +42,7 @@ NodeBindings::~NodeBindings() { WakeupEmbedThread(); uv_thread_join(&embed_thread_); uv_sem_destroy(&embed_sem_); + uv_timer_stop(&idle_timer_); } void NodeBindings::Initialize() { @@ -63,6 +64,10 @@ void NodeBindings::Initialize() { #endif } + // Init idle GC. + uv_timer_init(uv_default_loop(), &idle_timer_); + uv_timer_start(&idle_timer_, IdleCallback, 5000, 5000); + // Open node's error reporting system for browser process. node::g_standalone_mode = is_browser_; @@ -180,4 +185,9 @@ void NodeBindings::EmbedThreadRunner(void *arg) { } } +// static +void NodeBindings::IdleCallback(uv_timer_t*, int) { + v8::V8::IdleNotification(); +} + } // namespace atom diff --git a/common/node_bindings.h b/common/node_bindings.h index ef03424b85a1..cadf168ea7a1 100644 --- a/common/node_bindings.h +++ b/common/node_bindings.h @@ -67,12 +67,18 @@ class NodeBindings { // Thread to poll uv events. static void EmbedThreadRunner(void *arg); + // Do idle GC. + static void IdleCallback(uv_timer_t*, int); + // Whether the libuv loop has ended. bool embed_closed_; // Dummy handle to make uv's loop not quit. uv_async_t dummy_uv_handle_; + // Timer to do idle GC. + uv_timer_t idle_timer_; + // Thread for polling events. uv_thread_t embed_thread_;