From b7526eb3244942bc17243f90b87d8426494d02f0 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 28 Sep 2009 18:10:25 +0200 Subject: [PATCH] Add warning when coroutine stack size grows too large. For the moment too large is 10. --- src/events.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/events.cc b/src/events.cc index 39fed9db3f..387f8ca1a0 100644 --- a/src/events.cc +++ b/src/events.cc @@ -28,6 +28,7 @@ Persistent EventEmitter::constructor_template; /* Poor Man's coroutines */ static Promise *coroutine_top; +static int coroutine_stack_size; void EventEmitter::Initialize(Local ctemplate) { HandleScope scope; @@ -41,6 +42,7 @@ void EventEmitter::Initialize(Local ctemplate) { // All other prototype methods are defined in events.js coroutine_top = NULL; + coroutine_stack_size = 0; } static bool ReallyEmit(Handle self, @@ -176,6 +178,10 @@ void Promise::Block(void) { assert(prev_ == NULL); if (coroutine_top) prev_ = coroutine_top; coroutine_top = this; + coroutine_stack_size++; + if (coroutine_stack_size > 10) { + fprintf(stderr, "(node) WARNING: promise.wait() is being called too often.\n"); + } ev_loop(EV_DEFAULT_UC_ 0); @@ -187,6 +193,7 @@ void Promise::Destack() { ev_unloop(EV_DEFAULT_ EVUNLOOP_ONE); coroutine_top = prev_; prev_ = NULL; + coroutine_stack_size--; } void Promise::Detach(void) {