0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 15:25:19 +00:00

Use std::deque for timer_stack

In order to update limits at runtime we need the stack to be iterable.
This commit is contained in:
Stefan Siegl 2014-12-07 15:54:37 +01:00
parent e617662293
commit ab6df6f14f
2 changed files with 8 additions and 8 deletions

View File

@ -34,7 +34,7 @@ extern "C" {
#include <v8.h>
#include <chrono>
#include <stack>
#include <deque>
#include <thread>
#include <map>
@ -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<php_v8js_timer_ctx *> timer_stack;
std::deque<php_v8js_timer_ctx *> timer_stack;
std::thread *timer_thread;
std::mutex timer_mutex;
bool timer_stop;

12
v8js.cc
View File

@ -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<php_v8js_timer_ctx *>;
new(&v8js_globals->timer_stack) std::deque<php_v8js_timer_ctx *>;
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
}