Permalink
Browse files

core, refactor: revert to the previous code (v8 fixed the deadlock er…

…ror).
  • Loading branch information...
xicilion committed Oct 31, 2017
1 parent 6ddc436 commit b4cd3c1bfd983f1bbf502b2a82f6c9fe653a283e
Showing with 17 additions and 71 deletions.
  1. +1 −6 fibjs/include/Isolate.h
  2. +2 −0 fibjs/include/v8_api.h
  3. +7 −62 fibjs/src/base/Runtime.cpp
  4. +6 −0 fibjs/src/base/v8_api.cpp
  5. +0 −2 fibjs/src/coroutine/Fiber.cpp
  6. +1 −1 vender
View
@@ -88,11 +88,6 @@ class Isolate : public exlib::linkitem {
return m_isolate->GetCurrentContext();
}
bool IsInUse()
{
return m_in_use != 0;
}
void start_profiler();
public:
@@ -126,7 +121,7 @@ class Isolate : public exlib::linkitem {
int32_t m_idleFibers;
exlib::atomic m_pendding;
exlib::atomic m_in_use;
exlib::atomic m_has_timer;
int64_t m_fid;
View
@@ -10,6 +10,8 @@
namespace fibjs {
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
struct V8FrameInfo {
void* entry_fp;
void* handle;
View
@@ -66,13 +66,10 @@ Isolate::rt_base::rt_base(Isolate* cur)
fb->m_c_entry_fp_ = _fi.entry_fp;
fb->m_handler_ = _fi.handle;
m_isolate->m_in_use = 0;
}
Isolate::rt_base::~rt_base()
{
m_isolate->m_in_use = 1;
}
static void fb_GCCallback(v8::Isolate* js_isolate, v8::GCType type, v8::GCCallbackFlags flags)
@@ -191,72 +188,20 @@ void Isolate::start_profiler()
m_pendding.dec();
}
}
class CallbackData : public obj_base {
public:
CallbackData(Isolate* isolate, v8::InterruptCallback callback, void* data)
: m_isolate(isolate)
, m_callback(callback)
, m_data(data)
{
}
void invoke()
{
if (m_invoked.CompareAndSwap(0, 1) == 0)
m_callback(m_isolate->m_isolate, m_data);
}
public:
Isolate* m_isolate;
v8::InterruptCallback m_callback;
void* m_data;
exlib::atomic m_invoked;
};
static result_t js_timer(CallbackData* cd)
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
static result_t js_timer(Isolate* isolate)
{
JSFiber::scope s;
cd->invoke();
cd->Unref();
isolate->m_has_timer = 0;
InvokeApiInterruptCallbacks(isolate->m_isolate);
return 0;
}
static void _InterruptCallback(v8::Isolate* isolate, void* data)
{
CallbackData* cd = (CallbackData*)data;
cd->invoke();
cd->Unref();
}
void Isolate::RequestInterrupt(v8::InterruptCallback callback, void* data)
{
CallbackData* cd = new CallbackData(this, callback, data);
cd->Ref();
if (IsInUse()) {
cd->Ref();
m_isolate->RequestInterrupt(_InterruptCallback, cd);
exlib::OSThread::sleep(1);
if (!cd->m_invoked) {
cd->Ref();
syncCall(this, js_timer, cd);
}
} else {
cd->Ref();
syncCall(this, js_timer, cd);
exlib::OSThread::sleep(1);
if (IsInUse() && !cd->m_invoked) {
cd->Ref();
m_isolate->RequestInterrupt(_InterruptCallback, cd);
}
}
cd->Unref();
m_isolate->RequestInterrupt(callback, data);
if (m_has_timer.CompareAndSwap(0, 1) == 0)
syncCall(this, js_timer, this);
}
} /* namespace fibjs */
@@ -22,6 +22,12 @@
namespace fibjs {
void InvokeApiInterruptCallbacks(v8::Isolate* isolate)
{
v8::internal::Isolate* v8_isolate = (v8::internal::Isolate*)isolate;
v8_isolate->InvokeApiInterruptCallbacks();
}
V8FrameInfo save_fi(v8::Isolate* isolate)
{
v8::internal::Isolate* v8_isolate = (v8::internal::Isolate*)isolate;
@@ -68,9 +68,7 @@ void JSFiber::fiber_proc(void* p)
v8::HandleScope handle_scope(isolate->m_isolate);
AsyncEvent* ae = (AsyncEvent*)isolate->m_jobs.getHead();
isolate->m_in_use = 1;
hr = ae->js_invoke();
isolate->m_in_use = 0;
}
if (isolate->m_pendding.dec() == 0)

0 comments on commit b4cd3c1

Please sign in to comment.