Skip to content

Commit 9cec08e

Browse files
piscisaureusry
authored andcommitted
Batch of ev -> uv changes
1 parent 207901e commit 9cec08e

6 files changed

Lines changed: 91 additions & 100 deletions

File tree

src/node.cc

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <node_dtrace.h>
2828

2929
#include <locale.h>
30+
#include <signal.h>
3031
#include <stdio.h>
3132
#include <stdlib.h>
3233
#include <strings.h>
@@ -119,9 +120,9 @@ static uv_handle_t tick_spinner;
119120
static bool need_tick_cb;
120121
static Persistent<String> tick_callback_sym;
121122

122-
static ev_async eio_want_poll_notifier;
123-
static ev_async eio_done_poll_notifier;
124-
static ev_idle eio_poller;
123+
static uv_handle_t eio_want_poll_notifier;
124+
static uv_handle_t eio_done_poll_notifier;
125+
static uv_handle_t eio_poller;
125126

126127
// Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this
127128
// scoped at file-level rather than method-level to avoid excess stack usage.
@@ -134,52 +135,50 @@ static char getbuf[PATH_MAX + 1];
134135
//
135136
// A rather convoluted algorithm has been devised to determine when Node is
136137
// idle. You'll have to figure it out for yourself.
137-
static ev_check gc_check;
138-
static ev_idle gc_idle;
139-
static ev_timer gc_timer;
138+
static uv_handle_t gc_check;
139+
static uv_handle_t gc_idle;
140+
static uv_handle_t gc_timer;
140141
bool need_gc;
141142

142143

143144
#define FAST_TICK 0.7
144145
#define GC_WAIT_TIME 5.
145146
#define RPM_SAMPLES 100
146147
#define TICK_TIME(n) tick_times[(tick_time_head - (n)) % RPM_SAMPLES]
147-
static ev_tstamp tick_times[RPM_SAMPLES];
148+
static int64_t tick_times[RPM_SAMPLES];
148149
static int tick_time_head;
149150

151+
static void CheckStatus(uv_handle_t* watcher, int status);
152+
150153
static void StartGCTimer () {
151-
if (!ev_is_active(&gc_timer)) {
152-
ev_timer_start(EV_DEFAULT_UC_ &gc_timer);
153-
ev_unref(EV_DEFAULT_UC);
154+
if (!uv_is_active(&gc_timer)) {
155+
uv_timer_start(&node::gc_timer, node::CheckStatus, 5., 5.);
154156
}
155157
}
156158

157159
static void StopGCTimer () {
158-
if (ev_is_active(&gc_timer)) {
159-
ev_ref(EV_DEFAULT_UC);
160-
ev_timer_stop(EV_DEFAULT_UC_ &gc_timer);
160+
if (uv_is_active(&gc_timer)) {
161+
uv_timer_stop(&gc_timer);
161162
}
162163
}
163164

164-
static void Idle(EV_P_ ev_idle *watcher, int revents) {
165+
static void Idle(uv_handle_t* watcher, int status) {
165166
assert(watcher == &gc_idle);
166-
assert(revents == EV_IDLE);
167167

168168
//fprintf(stderr, "idle\n");
169169

170170
if (V8::IdleNotification()) {
171-
ev_idle_stop(EV_A_ watcher);
171+
uv_idle_stop(watcher);
172172
StopGCTimer();
173173
}
174174
}
175175

176176

177177
// Called directly after every call to select() (or epoll, or whatever)
178-
static void Check(EV_P_ ev_check *watcher, int revents) {
178+
static void Check(uv_handle_t* watcher, int status) {
179179
assert(watcher == &gc_check);
180-
assert(revents == EV_CHECK);
181180

182-
tick_times[tick_time_head] = ev_now(EV_DEFAULT_UC);
181+
tick_times[tick_time_head] = uv_now();
183182
tick_time_head = (tick_time_head + 1) % RPM_SAMPLES;
184183

185184
StartGCTimer();
@@ -198,7 +197,7 @@ static void Check(EV_P_ ev_check *watcher, int revents) {
198197
// Otherwise start the gc!
199198

200199
//fprintf(stderr, "start idle 2\n");
201-
ev_idle_start(EV_A_ &gc_idle);
200+
uv_idle_start(&node::gc_idle, node::Idle);
202201
}
203202

204203

@@ -270,42 +269,42 @@ static void CheckTick(uv_handle_t* handle, int status) {
270269
}
271270

272271

273-
static void DoPoll(EV_P_ ev_idle *watcher, int revents) {
272+
static void DoPoll(uv_handle_t* watcher, int status) {
274273
assert(watcher == &eio_poller);
275-
assert(revents == EV_IDLE);
276274

277275
//printf("eio_poller\n");
278276

279-
if (eio_poll() != -1) {
277+
if (eio_poll() != -1 && uv_is_active(&eio_poller)) {
280278
//printf("eio_poller stop\n");
281-
ev_idle_stop(EV_DEFAULT_UC_ watcher);
279+
uv_idle_stop(watcher);
280+
uv_unref();
282281
}
283282
}
284283

285284

286285
// Called from the main thread.
287-
static void WantPollNotifier(EV_P_ ev_async *watcher, int revents) {
286+
static void WantPollNotifier(uv_handle_t* watcher, int status) {
288287
assert(watcher == &eio_want_poll_notifier);
289-
assert(revents == EV_ASYNC);
290288

291289
//printf("want poll notifier\n");
292290

293-
if (eio_poll() == -1) {
291+
if (eio_poll() == -1 && !uv_is_active(&eio_poller)) {
294292
//printf("eio_poller start\n");
295-
ev_idle_start(EV_DEFAULT_UC_ &eio_poller);
293+
uv_idle_start(&eio_poller, node::DoPoll);
294+
uv_ref();
296295
}
297296
}
298297

299298

300-
static void DonePollNotifier(EV_P_ ev_async *watcher, int revents) {
299+
static void DonePollNotifier(uv_handle_t* watcher, int revents) {
301300
assert(watcher == &eio_done_poll_notifier);
302-
assert(revents == EV_ASYNC);
303301

304302
//printf("done poll notifier\n");
305303

306-
if (eio_poll() != -1) {
304+
if (eio_poll() != -1 && uv_is_active(&eio_poller)) {
307305
//printf("eio_poller stop\n");
308-
ev_idle_stop(EV_DEFAULT_UC_ &eio_poller);
306+
uv_idle_stop(&eio_poller);
307+
uv_unref();
309308
}
310309
}
311310

@@ -314,14 +313,14 @@ static void DonePollNotifier(EV_P_ ev_async *watcher, int revents) {
314313
// request (that is, one of the node.fs.* functions) has completed.
315314
static void EIOWantPoll(void) {
316315
// Signal the main thread that eio_poll need to be processed.
317-
ev_async_send(EV_DEFAULT_UC_ &eio_want_poll_notifier);
316+
uv_async_send(&eio_want_poll_notifier);
318317
}
319318

320319

321320
static void EIODonePoll(void) {
322321
// Signal the main thread that we should stop calling eio_poll().
323322
// from the idle watcher.
324-
ev_async_send(EV_DEFAULT_UC_ &eio_done_poll_notifier);
323+
uv_async_send(&eio_done_poll_notifier);
325324
}
326325

327326

@@ -1508,28 +1507,27 @@ v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
15081507
}
15091508

15101509

1511-
static void CheckStatus(EV_P_ ev_timer *watcher, int revents) {
1510+
static void CheckStatus(uv_handle_t* watcher, int status) {
15121511
assert(watcher == &gc_timer);
1513-
assert(revents == EV_TIMEOUT);
15141512

15151513
// check memory
1516-
if (!ev_is_active(&gc_idle)) {
1514+
if (!uv_is_active(&gc_idle)) {
15171515
HeapStatistics stats;
15181516
V8::GetHeapStatistics(&stats);
15191517
if (stats.total_heap_size() > 1024 * 1024 * 128) {
15201518
// larger than 128 megs, just start the idle watcher
1521-
ev_idle_start(EV_A_ &gc_idle);
1519+
uv_idle_start(&node::gc_idle, node::Idle);
15221520
return;
15231521
}
15241522
}
15251523

1526-
double d = ev_now(EV_DEFAULT_UC) - TICK_TIME(3);
1524+
double d = uv_now() - TICK_TIME(3);
15271525

15281526
//printfb("timer d = %f\n", d);
15291527

15301528
if (d >= GC_WAIT_TIME - 1.) {
15311529
//fprintf(stderr, "start idle\n");
1532-
ev_idle_start(EV_A_ &gc_idle);
1530+
uv_idle_start(&node::gc_idle, node::Idle);
15331531
}
15341532
}
15351533

@@ -1784,12 +1782,11 @@ void FatalException(TryCatch &try_catch) {
17841782
}
17851783

17861784

1787-
static ev_async debug_watcher;
1785+
static uv_handle_t debug_watcher;
17881786

1789-
static void DebugMessageCallback(EV_P_ ev_async *watcher, int revents) {
1787+
static void DebugMessageCallback(uv_handle_t* watcher, int status) {
17901788
HandleScope scope;
17911789
assert(watcher == &debug_watcher);
1792-
assert(revents == EV_ASYNC);
17931790
Debug::ProcessDebugMessages();
17941791
}
17951792

@@ -1799,7 +1796,7 @@ static void DebugMessageDispatch(void) {
17991796

18001797
// Send a signal to our main thread saying that it should enter V8 to
18011798
// handle the message.
1802-
ev_async_send(EV_DEFAULT_UC_ &debug_watcher);
1799+
uv_async_send(&debug_watcher);
18031800
}
18041801

18051802
static void DebugBreakMessageHandler(const Debug::Message& message) {
@@ -1989,8 +1986,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
19891986
versions->Set(String::NewSymbol("node"), String::New(NODE_VERSION+1));
19901987
versions->Set(String::NewSymbol("v8"), String::New(V8::GetVersion()));
19911988
versions->Set(String::NewSymbol("ares"), String::New(ARES_VERSION_STR));
1992-
snprintf(buf, 20, "%d.%d", ev_version_major(), ev_version_minor());
1993-
versions->Set(String::NewSymbol("ev"), String::New(buf));
1989+
snprintf(buf, 20, "%d.%d", UV_VERSION_MAJOR, UV_VERSION_MINOR);
1990+
versions->Set(String::NewSymbol("uv"), String::New(buf));
19941991
#ifdef HAVE_OPENSSL
19951992
// Stupid code to slice out the version string.
19961993
int c, l = strlen(OPENSSL_VERSION_TEXT);
@@ -2365,28 +2362,26 @@ char** Init(int argc, char *argv[]) {
23652362
uv_idle_init(&node::tick_spinner, NULL, NULL);
23662363
uv_unref();
23672364

2368-
ev_check_init(&node::gc_check, node::Check);
2369-
ev_check_start(EV_DEFAULT_UC_ &node::gc_check);
2370-
ev_unref(EV_DEFAULT_UC);
2365+
uv_check_init(&node::gc_check, NULL, NULL);
2366+
uv_check_start(&node::gc_check, node::Check);
2367+
uv_unref();
23712368

2372-
ev_idle_init(&node::gc_idle, node::Idle);
2373-
ev_timer_init(&node::gc_timer, node::CheckStatus, 5., 5.);
2369+
uv_idle_init(&node::gc_idle, NULL, NULL);
2370+
uv_unref();
23742371

2372+
uv_timer_init(&node::gc_timer, NULL, NULL);
2373+
uv_unref();
23752374

23762375
// Setup the EIO thread pool. It requires 3, yes 3, watchers.
23772376
{
2378-
ev_idle_init(&node::eio_poller, node::DoPoll);
2379-
// TODO Probably don't need to start this each time.
2380-
// Avoids failing on test/simple/test-eio-race3.js though
2381-
ev_idle_start(EV_DEFAULT_UC_ &eio_poller);
2377+
uv_idle_init(&node::eio_poller, NULL, NULL);
2378+
uv_idle_start(&eio_poller, node::DoPoll);
23822379

2383-
ev_async_init(&node::eio_want_poll_notifier, node::WantPollNotifier);
2384-
ev_async_start(EV_DEFAULT_UC_ &node::eio_want_poll_notifier);
2385-
ev_unref(EV_DEFAULT_UC);
2380+
uv_async_init(&node::eio_want_poll_notifier, node::WantPollNotifier, NULL, NULL);
2381+
uv_unref();
23862382

2387-
ev_async_init(&node::eio_done_poll_notifier, node::DonePollNotifier);
2388-
ev_async_start(EV_DEFAULT_UC_ &node::eio_done_poll_notifier);
2389-
ev_unref(EV_DEFAULT_UC);
2383+
uv_async_init(&node::eio_done_poll_notifier, node::DonePollNotifier, NULL, NULL);
2384+
uv_unref();
23902385

23912386
eio_init(node::EIOWantPoll, node::EIODonePoll);
23922387
// Don't handle more than 10 reqs on each eio_poll(). This is to avoid
@@ -2397,20 +2392,16 @@ char** Init(int argc, char *argv[]) {
23972392
V8::SetFatalErrorHandler(node::OnFatalError);
23982393

23992394

2400-
// Initialize the async watcher for receiving messages from the debug
2401-
// thread and marshal it into the main thread. DebugMessageCallback()
2402-
// is called from the main thread to execute a random bit of javascript
2403-
// - which will give V8 control so it can handle whatever new message
2404-
// had been received on the debug thread.
2405-
ev_async_init(&node::debug_watcher, node::DebugMessageCallback);
2406-
ev_set_priority(&node::debug_watcher, EV_MAXPRI);
24072395
// Set the callback DebugMessageDispatch which is called from the debug
24082396
// thread.
24092397
Debug::SetDebugMessageDispatchHandler(node::DebugMessageDispatch);
2410-
// Start the async watcher.
2411-
ev_async_start(EV_DEFAULT_UC_ &node::debug_watcher);
2398+
// Initialize the async watcher. DebugMessageCallback() is called from the
2399+
// main thread to execute a random bit of javascript - which will give V8
2400+
// control so it can handle whatever new message had been received on the
2401+
// debug thread.
2402+
uv_async_init(&node::debug_watcher, node::DebugMessageCallback, NULL, NULL);
24122403
// unref it so that we exit the event loop despite it being active.
2413-
ev_unref(EV_DEFAULT_UC);
2404+
uv_unref();
24142405

24152406

24162407
// If the --debug flag was specified then initialize the debug thread.
@@ -2470,7 +2461,7 @@ int Start(int argc, char *argv[]) {
24702461
// All our arguments are loaded. We've evaluated all of the scripts. We
24712462
// might even have created TCP servers. Now we enter the main eventloop. If
24722463
// there are no watchers on the loop (except for the ones that were
2473-
// ev_unref'd) then this function exits. As long as there are active
2464+
// uv_unref'd) then this function exits. As long as there are active
24742465
// watchers, it blocks.
24752466
uv_run();
24762467

src/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifndef SRC_NODE_H_
2323
#define SRC_NODE_H_
2424

25-
#include <ev.h>
25+
#include <uv.h>
2626
#include <eio.h>
2727
#include <v8.h>
2828
#include <sys/types.h> /* struct stat */

src/node_constants.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <node_constants.h>
2323

24-
#include <ev.h>
24+
#include <uv.h>
2525

2626
#include <errno.h>
2727
#include <unistd.h>
@@ -44,9 +44,6 @@ namespace node {
4444
using namespace v8;
4545

4646
void DefineConstants(Handle<Object> target) {
47-
NODE_DEFINE_CONSTANT(target, EV_MINPRI);
48-
NODE_DEFINE_CONSTANT(target, EV_MAXPRI);
49-
5047
// file access modes
5148
NODE_DEFINE_CONSTANT(target, O_RDONLY);
5249
NODE_DEFINE_CONSTANT(target, O_WRONLY);

src/node_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int After(eio_req *req) {
8888

8989
Persistent<Function> *callback = cb_unwrap(req->data);
9090

91-
ev_unref(EV_DEFAULT_UC);
91+
uv_unref();
9292

9393
// there is always at least one argument. "error"
9494
int argc = 1;
@@ -213,7 +213,7 @@ static int After(eio_req *req) {
213213
eio_req *req = eio_##func(__VA_ARGS__, EIO_PRI_DEFAULT, After, \
214214
cb_persist(callback)); \
215215
assert(req); \
216-
ev_ref(EV_DEFAULT_UC); \
216+
uv_ref(); \
217217
return Undefined();
218218

219219
static Handle<Value> Close(const Arguments& args) {

src/node_script.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <node.h>
2626
#include <node_object_wrap.h>
2727
#include <v8.h>
28-
#include <ev.h>
28+
#include <uv.h>
2929

3030
namespace node {
3131

0 commit comments

Comments
 (0)