mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 22:08:40 +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:
parent
e617662293
commit
ab6df6f14f
@ -34,7 +34,7 @@ extern "C" {
|
|||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <stack>
|
#include <deque>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -222,7 +222,7 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js)
|
|||||||
bool use_date; /* Generate JS Date objects instead of PHP DateTime */
|
bool use_date; /* Generate JS Date objects instead of PHP DateTime */
|
||||||
|
|
||||||
// Timer thread globals
|
// Timer thread globals
|
||||||
std::stack<php_v8js_timer_ctx *> timer_stack;
|
std::deque<php_v8js_timer_ctx *> timer_stack;
|
||||||
std::thread *timer_thread;
|
std::thread *timer_thread;
|
||||||
std::mutex timer_mutex;
|
std::mutex timer_mutex;
|
||||||
bool timer_stop;
|
bool timer_stop;
|
||||||
|
12
v8js.cc
12
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->time_point = from + duration;
|
||||||
timer_ctx->v8js_ctx = c;
|
timer_ctx->v8js_ctx = c;
|
||||||
timer_ctx->killed = false;
|
timer_ctx->killed = false;
|
||||||
V8JSG(timer_stack).push(timer_ctx);
|
V8JSG(timer_stack).push_front(timer_ctx);
|
||||||
|
|
||||||
V8JSG(timer_mutex).unlock();
|
V8JSG(timer_mutex).unlock();
|
||||||
}
|
}
|
||||||
@ -1089,7 +1089,7 @@ static void php_v8js_timer_thread(TSRMLS_D)
|
|||||||
|
|
||||||
if (V8JSG(timer_stack).size()) {
|
if (V8JSG(timer_stack).size()) {
|
||||||
// Get the current timer context
|
// 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;
|
php_v8js_ctx *c = timer_ctx->v8js_ctx;
|
||||||
|
|
||||||
// Get memory usage statistics for the isolate
|
// 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
|
/* Pop our context from the stack and read (possibly updated) limits
|
||||||
* into local variables. */
|
* into local variables. */
|
||||||
V8JSG(timer_mutex).lock();
|
V8JSG(timer_mutex).lock();
|
||||||
php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).top();
|
php_v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).front();
|
||||||
V8JSG(timer_stack).pop();
|
V8JSG(timer_stack).pop_front();
|
||||||
V8JSG(timer_mutex).unlock();
|
V8JSG(timer_mutex).unlock();
|
||||||
|
|
||||||
time_limit = timer_ctx->time_limit;
|
time_limit = timer_ctx->time_limit;
|
||||||
@ -2180,7 +2180,7 @@ static PHP_GINIT_FUNCTION(v8js)
|
|||||||
v8js_globals->timer_thread = NULL;
|
v8js_globals->timer_thread = NULL;
|
||||||
v8js_globals->timer_stop = false;
|
v8js_globals->timer_stop = false;
|
||||||
new(&v8js_globals->timer_mutex) std::mutex;
|
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->fatal_error_abort = 0;
|
||||||
v8js_globals->error_num = 0;
|
v8js_globals->error_num = 0;
|
||||||
@ -2207,7 +2207,7 @@ static PHP_GSHUTDOWN_FUNCTION(v8js)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
v8js_globals->timer_stack.~stack();
|
v8js_globals->timer_stack.~deque();
|
||||||
v8js_globals->timer_mutex.~mutex();
|
v8js_globals->timer_mutex.~mutex();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user