@@ -102,8 +102,21 @@ static ev_tstamp last_active;
102
102
static ev_timer gc_timer;
103
103
static ev_check gc_check;
104
104
static ev_idle gc_idle;
105
- static bool needs_gc;
106
- #define GC_INTERVAL 2.0
105
+ #define GC_INTERVAL 1.0
106
+
107
+ static void gc_timer_start () {
108
+ if (!ev_is_active (&gc_timer)) {
109
+ ev_timer_start (EV_DEFAULT_UC_ &gc_timer);
110
+ ev_unref (EV_DEFAULT_UC);
111
+ }
112
+ }
113
+
114
+ static void gc_timer_stop () {
115
+ if (ev_is_active (&gc_timer)) {
116
+ ev_ref (EV_DEFAULT_UC);
117
+ ev_timer_stop (EV_DEFAULT_UC_ &gc_timer);
118
+ }
119
+ }
107
120
108
121
109
122
static void CheckIdleness (EV_P_ ev_timer *watcher, int revents) {
@@ -115,15 +128,10 @@ static void CheckIdleness(EV_P_ ev_timer *watcher, int revents) {
115
128
ev_tstamp idle_time = ev_now (EV_DEFAULT_UC) - last_active;
116
129
117
130
if (idle_time > GC_INTERVAL) {
118
- if (needs_gc) {
119
- needs_gc = false ;
120
- if (!V8::IdleNotification ()) {
121
- ev_idle_start (EV_DEFAULT_UC_ &gc_idle);
122
- }
131
+ if (!V8::IdleNotification ()) {
132
+ ev_idle_start (EV_DEFAULT_UC_ &gc_idle);
123
133
}
124
- // reset the timer
125
- gc_timer.repeat = GC_INTERVAL;
126
- ev_timer_again (EV_DEFAULT_UC_ watcher);
134
+ gc_timer_stop ();
127
135
}
128
136
}
129
137
@@ -136,8 +144,8 @@ static void NotifyIdleness(EV_P_ ev_idle *watcher, int revents) {
136
144
137
145
if (V8::IdleNotification ()) {
138
146
ev_idle_stop (EV_A_ watcher);
147
+ gc_timer_stop ();
139
148
}
140
- needs_gc = false ;
141
149
}
142
150
143
151
@@ -149,23 +157,18 @@ static void Activity(EV_P_ ev_check *watcher, int revents) {
149
157
150
158
// Don't count GC watchers as activity.
151
159
152
- pending -= ev_is_pending (&gc_timer);
153
- pending -= ev_is_pending (&gc_idle);
154
- pending -= ev_is_pending (&next_tick_watcher);
155
- // if (ev_is_pending(&gc_check)) pending--; // This probably never happens?
160
+ if (ev_is_pending (&gc_timer)) pending--;
161
+ if (ev_is_pending (&gc_idle)) pending--;
162
+ if (ev_is_pending (&gc_check)) pending--;
163
+
164
+ assert (pending >= 0 );
156
165
157
166
// fprintf(stderr, "activity, pending: %d\n", pending);
158
167
159
168
if (pending) {
160
169
last_active = ev_now (EV_DEFAULT_UC);
161
170
ev_idle_stop (EV_DEFAULT_UC_ &gc_idle);
162
-
163
- if (!needs_gc) {
164
- gc_timer.repeat = GC_INTERVAL;
165
- ev_timer_again (EV_DEFAULT_UC_ &gc_timer);
166
- }
167
-
168
- needs_gc = true ;
171
+ gc_timer_start ();
169
172
}
170
173
}
171
174
@@ -1594,10 +1597,7 @@ int main(int argc, char *argv[]) {
1594
1597
1595
1598
ev_idle_init (&node::tick_spinner, node::Spin);
1596
1599
1597
- ev_init (&node::gc_timer, node::CheckIdleness);
1598
- node::gc_timer.repeat = GC_INTERVAL;
1599
- ev_timer_again (EV_DEFAULT_UC_ &node::gc_timer);
1600
- ev_unref (EV_DEFAULT_UC);
1600
+ ev_timer_init (&node::gc_timer, node::CheckIdleness, 2 *GC_INTERVAL, 2 *GC_INTERVAL);
1601
1601
1602
1602
ev_check_init (&node::gc_check, node::Activity);
1603
1603
ev_check_start (EV_DEFAULT_UC_ &node::gc_check);
0 commit comments