0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 18:41:52 +00:00

Fix globals ptr passing wrt. timer thread

This commit is contained in:
Stefan Siegl 2015-09-28 22:03:24 +02:00
parent fd32ec0fa9
commit c6136ec3d2
5 changed files with 21 additions and 27 deletions

View File

@ -42,7 +42,6 @@ extern "C" {
#include "v8js_class.h" #include "v8js_class.h"
#include "v8js_v8.h" #include "v8js_v8.h"
#include "v8js_timer.h"
#ifndef PATH_MAX #ifndef PATH_MAX
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment /* 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 */ /* 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); 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 */ /* Module globals */
ZEND_BEGIN_MODULE_GLOBALS(v8js) ZEND_BEGIN_MODULE_GLOBALS(v8js)

View File

@ -701,7 +701,7 @@ static PHP_METHOD(V8Js, setTimeLimit)
if (c->in_execution && time_limit && !V8JSG(timer_thread)) { if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
/* If timer thread is not started already and we now impose a time limit /* If timer thread is not started already and we now impose a time limit
* finally install the timer. */ * 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 (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
/* If timer thread is not started already and we now impose a memory limit /* If timer thread is not started already and we now impose a memory limit
* finally install the timer. */ * 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));
} }
} }
/* }}} */ /* }}} */

View File

@ -28,14 +28,12 @@ extern "C" {
#include "php_v8js_macros.h" #include "php_v8js_macros.h"
#include "v8js_v8.h" #include "v8js_v8.h"
#include "v8js_exceptions.h" #include "v8js_exceptions.h"
#include "v8js_timer.h"
static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* {{{ */ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* {{{ */
#ifdef ZTS zend_v8js_globals *globals = static_cast<zend_v8js_globals *>(data);
// @fixme
//TSRMLS_D = (void ***) data;
#endif
if (!V8JSG(timer_stack).size()) { if (!globals->timer_stack.size()) {
return; return;
} }
@ -43,10 +41,10 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
v8::HeapStatistics hs; v8::HeapStatistics hs;
isolate->GetHeapStatistics(&hs); isolate->GetHeapStatistics(&hs);
V8JSG(timer_mutex).lock(); globals->timer_mutex.lock();
for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin(); for (std::deque< v8js_timer_ctx* >::iterator it = globals->timer_stack.begin();
it != V8JSG(timer_stack).end(); it ++) { it != globals->timer_stack.end(); it ++) {
v8js_timer_ctx *timer_ctx = *it; v8js_timer_ctx *timer_ctx = *it;
v8js_ctx *c = timer_ctx->ctx; 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(); globals->timer_mutex.lock();
if (V8JSG(timer_stack).size()) { if (globals->timer_stack.size()) {
v8js_timer_ctx *timer_ctx = V8JSG(timer_stack).front(); v8js_timer_ctx *timer_ctx = globals->timer_stack.front();
v8js_ctx *c = timer_ctx->ctx; v8js_ctx *c = timer_ctx->ctx;
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now(); 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 * directly call GetHeapStatistics here, since we don't have
* a v8::Locker on the isolate, but are expected to hold one, * a v8::Locker on the isolate, but are expected to hold one,
* and cannot aquire it as v8 is executing the script ... */ * and cannot aquire it as v8 is executing the script ... */
void *data = NULL; c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, static_cast<void *>(globals));
#ifdef ZTS
// @fixme
//data = (void *) TSRMLS_C;
#endif
c->isolate->RequestInterrupt(v8js_timer_interrupt_handler, data);
} }
} }
V8JSG(timer_mutex).unlock(); globals->timer_mutex.unlock();
// Sleep for 10ms // Sleep for 10ms
#ifdef _WIN32 #ifdef _WIN32

View File

@ -24,7 +24,7 @@ struct v8js_timer_ctx
bool killed; 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); void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c TSRMLS_DC);
#endif /* V8JS_TIMER_H */ #endif /* V8JS_TIMER_H */

View File

@ -98,7 +98,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
// If timer thread is not running then start it // If timer thread is not running then start it
if (!V8JSG(timer_thread)) { if (!V8JSG(timer_thread)) {
// If not, start 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));
} }
} }