From ab6df6f14f27de42a1f52c092deba410bdbc0160 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sun, 7 Dec 2014 15:54:37 +0100 Subject: [PATCH] Use std::deque for timer_stack In order to update limits at runtime we need the stack to be iterable. --- php_v8js_macros.h | 4 ++-- v8js.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index a06e5b3..dc99da2 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -34,7 +34,7 @@ extern "C" { #include #include -#include +#include #include #include @@ -222,7 +222,7 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js) bool use_date; /* Generate JS Date objects instead of PHP DateTime */ // Timer thread globals - std::stack timer_stack; + std::deque timer_stack; std::thread *timer_thread; std::mutex timer_mutex; bool timer_stop; diff --git a/v8js.cc b/v8js.cc index 921ce42..de6332f 100644 --- a/v8js.cc +++ b/v8js.cc @@ -1069,7 +1069,7 @@ static void php_v8js_timer_push(long time_limit, long memory_limit, php_v8js_ctx timer_ctx->time_point = from + duration; timer_ctx->v8js_ctx = c; timer_ctx->killed = false; - V8JSG(timer_stack).push(timer_ctx); + V8JSG(timer_stack).push_front(timer_ctx); V8JSG(timer_mutex).unlock(); } @@ -1089,7 +1089,7 @@ static void php_v8js_timer_thread(TSRMLS_D) if (V8JSG(timer_stack).size()) { // Get the current timer context - php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).top(); + php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).front(); php_v8js_ctx *c = timer_ctx->v8js_ctx; // Get memory usage statistics for the isolate @@ -1223,8 +1223,8 @@ static void php_v8js_call_v8(php_v8js_ctx *c, zval **return_value, /* Pop our context from the stack and read (possibly updated) limits * into local variables. */ V8JSG(timer_mutex).lock(); - php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).top(); - V8JSG(timer_stack).pop(); + php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).front(); + V8JSG(timer_stack).pop_front(); V8JSG(timer_mutex).unlock(); time_limit = timer_ctx->time_limit; @@ -2180,7 +2180,7 @@ static PHP_GINIT_FUNCTION(v8js) v8js_globals->timer_thread = NULL; v8js_globals->timer_stop = false; new(&v8js_globals->timer_mutex) std::mutex; - new(&v8js_globals->timer_stack) std::stack; + new(&v8js_globals->timer_stack) std::deque; v8js_globals->fatal_error_abort = 0; v8js_globals->error_num = 0; @@ -2207,7 +2207,7 @@ static PHP_GSHUTDOWN_FUNCTION(v8js) } #ifdef ZTS - v8js_globals->timer_stack.~stack(); + v8js_globals->timer_stack.~deque(); v8js_globals->timer_mutex.~mutex(); #endif }