mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 07:01:52 +00:00
Fix globals ptr passing wrt. timer thread
This commit is contained in:
parent
fd32ec0fa9
commit
c6136ec3d2
@ -42,7 +42,6 @@ extern "C" {
|
||||
|
||||
#include "v8js_class.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_timer.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
|
||||
@ -99,7 +98,9 @@ void v8js_accessor_ctx_dtor(v8js_accessor_ctx * TSRMLS_DC);
|
||||
/* Register accessors into passed object */
|
||||
void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
||||
|
||||
/* Resource declaration */
|
||||
|
||||
/* Forward declarations */
|
||||
struct v8js_timer_ctx;
|
||||
|
||||
/* Module globals */
|
||||
ZEND_BEGIN_MODULE_GLOBALS(v8js)
|
||||
|
@ -701,7 +701,7 @@ static PHP_METHOD(V8Js, setTimeLimit)
|
||||
if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
|
||||
/* If timer thread is not started already and we now impose a time limit
|
||||
* finally install the timer. */
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@ -732,7 +732,7 @@ static PHP_METHOD(V8Js, setMemoryLimit)
|
||||
if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
|
||||
/* If timer thread is not started already and we now impose a memory limit
|
||||
* finally install the timer. */
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -28,14 +28,12 @@ extern "C" {
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_exceptions.h"
|
||||
#include "v8js_timer.h"
|
||||
|
||||
static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* {{{ */
|
||||
#ifdef ZTS
|
||||
// @fixme
|
||||
//TSRMLS_D = (void ***) data;
|
||||
#endif
|
||||
zend_v8js_globals *globals = static_cast<zend_v8js_globals *>(data);
|
||||
|
||||
if (!V8JSG(timer_stack).size()) {
|
||||
if (!globals->timer_stack.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -43,10 +41,10 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
|
||||
v8::HeapStatistics hs;
|
||||
isolate->GetHeapStatistics(&hs);
|
||||
|
||||
V8JSG(timer_mutex).lock();
|
||||
globals->timer_mutex.lock();
|
||||
|
||||
for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
|
||||
it != V8JSG(timer_stack).end(); it ++) {
|
||||
for (std::deque< v8js_timer_ctx* >::iterator it = globals->timer_stack.begin();
|
||||
it != globals->timer_stack.end(); it ++) {
|
||||
v8js_timer_ctx *timer_ctx = *it;
|
||||
v8js_ctx *c = timer_ctx->ctx;
|
||||
|
||||
@ -61,17 +59,17 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
|
||||
}
|
||||
}
|
||||
|
||||
V8JSG(timer_mutex).unlock();
|
||||
globals->timer_mutex.unlock();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void v8js_timer_thread(TSRMLS_D) /* {{{ */
|
||||
void v8js_timer_thread(zend_v8js_globals *globals) /* {{{ */
|
||||
{
|
||||
while (!V8JSG(timer_stop)) {
|
||||
while (!globals->timer_stop) {
|
||||
|
||||
V8JSG(timer_mutex).lock();
|
||||
if (V8JSG(timer_stack).size()) {
|
||||
v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).front();
|
||||
globals->timer_mutex.lock();
|
||||
if (globals->timer_stack.size()) {
|
||||
v8js_timer_ctx *timer_ctx = globals->timer_stack.front();
|
||||
v8js_ctx *c = timer_ctx->ctx;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
|
||||
|
||||
@ -90,15 +88,10 @@ void v8js_timer_thread(TSRMLS_D) /* {{{ */
|
||||
* directly call GetHeapStatistics here, since we don't have
|
||||
* a v8::Locker on the isolate, but are expected to hold one,
|
||||
* and cannot aquire it as v8 is executing the script ... */
|
||||
void *data = NULL;
|
||||
#ifdef ZTS
|
||||
// @fixme
|
||||
//data = (void *) TSRMLS_C;
|
||||
#endif
|
||||
c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, data);
|
||||
c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, static_cast<void *>(globals));
|
||||
}
|
||||
}
|
||||
V8JSG(timer_mutex).unlock();
|
||||
globals->timer_mutex.unlock();
|
||||
|
||||
// Sleep for 10ms
|
||||
#ifdef _WIN32
|
||||
|
@ -24,7 +24,7 @@ struct v8js_timer_ctx
|
||||
bool killed;
|
||||
};
|
||||
|
||||
void v8js_timer_thread(TSRMLS_D);
|
||||
void v8js_timer_thread(zend_v8js_globals *globals);
|
||||
void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c TSRMLS_DC);
|
||||
|
||||
#endif /* V8JS_TIMER_H */
|
||||
|
@ -98,7 +98,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
|
||||
// If timer thread is not running then start it
|
||||
if (!V8JSG(timer_thread)) {
|
||||
// If not, start timer thread
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
|
||||
V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user