Permalink
Browse files

core, feat: save the status of isolate.

  • Loading branch information...
xicilion committed Oct 17, 2017
1 parent 5b2c83f commit 838295b4be6c2af5d76a100f0a2f1b595b3d50b7
Showing with 40 additions and 16 deletions.
  1. +21 −10 fibjs/include/Isolate.h
  2. +16 −6 fibjs/src/base/Runtime.cpp
  3. +3 −0 fibjs/src/coroutine/Fiber.cpp
View
@@ -33,20 +33,26 @@ class JSFiber;
class LruCache;
class File_base;
struct V8FrameInfo {
void* entry_fp;
void* handle;
};
class Isolate : public exlib::linkitem {
public:
class rt {
class rt_base {
public:
rt(Isolate* cur = NULL);
rt_base(Isolate* cur = NULL);
~rt_base();
protected:
Isolate* m_isolate;
};
class rt : public rt_base {
public:
rt(Isolate* cur = NULL)
: rt_base(cur)
, unlocker(m_isolate->m_isolate)
{
}
private:
v8::Isolate* m_isolate;
V8FrameInfo m_fi;
v8::Unlocker unlocker;
};
@@ -82,6 +88,11 @@ class Isolate : public exlib::linkitem {
return m_isolate->GetCurrentContext();
}
bool IsInUse()
{
return m_in_use != 0;
}
public:
int32_t m_id;
exlib::string m_fname;
@@ -113,7 +124,7 @@ class Isolate : public exlib::linkitem {
int32_t m_idleFibers;
exlib::atomic m_pendding;
exlib::atomic m_has_timer;
exlib::atomic m_in_use;
int64_t m_fid;
View
@@ -56,17 +56,27 @@ exlib::LockedList<Isolate> s_isolates;
exlib::atomic s_iso_id;
extern int32_t stack_size;
struct V8FrameInfo {
void* entry_fp;
void* handle;
};
V8FrameInfo save_fi(v8::Isolate* isolate);
Isolate::rt::rt(Isolate* cur)
: m_isolate((cur ? cur : Isolate::current())->m_isolate)
, m_fi(save_fi(m_isolate))
, unlocker(m_isolate)
Isolate::rt_base::rt_base(Isolate* cur)
: m_isolate((cur ? cur : Isolate::current()))
{
JSFiber* fb = JSFiber::current();
V8FrameInfo _fi = save_fi(m_isolate->m_isolate);
fb->m_c_entry_fp_ = _fi.entry_fp;
fb->m_handler_ = _fi.handle;
fb->m_c_entry_fp_ = m_fi.entry_fp;
fb->m_handler_ = m_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)
@@ -69,7 +69,10 @@ 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 838295b

Please sign in to comment.