Permalink
Browse files

core, refactor: move RequestInterrupt into isolate.

  • Loading branch information...
xicilion committed Oct 15, 2017
1 parent eb4d6bc commit 7c9a6cba3d8b4c64c5f13b8aeb4ab9f104ddf90e
Showing with 22 additions and 24 deletions.
  1. +3 −0 fibjs/include/Isolate.h
  2. +16 −0 fibjs/src/base/Runtime.cpp
  3. +3 −24 fibjs/src/global/Timer.cpp
View
@@ -57,6 +57,8 @@ class Isolate : public exlib::linkitem {
static Isolate* current();
void init();
void RequestInterrupt(v8::InterruptCallback callback, void* data);
v8::Local<v8::String> NewString(const char* data, int length = -1)
{
return fibjs::NewString(m_isolate, data, length);
@@ -111,6 +113,7 @@ class Isolate : public exlib::linkitem {
int32_t m_idleFibers;
exlib::atomic m_pendding;
exlib::atomic m_has_timer;
int64_t m_fid;
View
@@ -170,4 +170,20 @@ void Isolate::init()
m_topSandbox->initRoot();
}
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
static result_t js_timer(Isolate* isolate)
{
JSFiber::scope s;
isolate->m_has_timer = 0;
InvokeApiInterruptCallbacks(isolate->m_isolate);
return 0;
}
void Isolate::RequestInterrupt(v8::InterruptCallback callback, void* data)
{
m_isolate->RequestInterrupt(callback, data);
if (m_has_timer.CompareAndSwap(0, 1) == 0)
syncCall(this, js_timer, this);
}
} /* namespace fibjs */
View
@@ -14,8 +14,6 @@
namespace fibjs {
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
#define TIMEOUT_MAX 2147483647 // 2^31-1
class JSTimer : public Timer {
@@ -42,14 +40,9 @@ class JSTimer : public Timer {
{
Isolate* isolate = holder();
if (m_hr) {
isolate->m_isolate->RequestInterrupt(_InterruptCallback, this);
if (m_has_worker.CompareAndSwap(0, 1) == 0) {
Ref();
syncCall(isolate, js_worker, this);
}
} else
if (m_hr)
isolate->RequestInterrupt(_InterruptCallback, this);
else
syncCall(isolate, _callback, this);
}
@@ -92,22 +85,8 @@ class JSTimer : public Timer {
}
}
static result_t js_worker(JSTimer* pThis)
{
JSFiber::scope s;
Isolate* isolate = pThis->holder();
InvokeApiInterruptCallbacks(isolate->m_isolate);
pThis->m_has_worker = 0;
pThis->Unref();
return 0;
}
private:
bool m_hr;
exlib::atomic m_has_worker;
bool m_clear_pendding;
QuickArray<v8::Global<v8::Value>> m_argv;
v8::Global<v8::Function> m_callback;

0 comments on commit 7c9a6cb

Please sign in to comment.