Skip to content

Commit b4cd3c1

Browse files
committed
core, refactor: revert to the previous code (v8 fixed the deadlock error).
1 parent 6ddc436 commit b4cd3c1

File tree

6 files changed

+17
-71
lines changed

6 files changed

+17
-71
lines changed

fibjs/include/Isolate.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ class Isolate : public exlib::linkitem {
8888
return m_isolate->GetCurrentContext();
8989
}
9090

91-
bool IsInUse()
92-
{
93-
return m_in_use != 0;
94-
}
95-
9691
void start_profiler();
9792

9893
public:
@@ -126,7 +121,7 @@ class Isolate : public exlib::linkitem {
126121
int32_t m_idleFibers;
127122

128123
exlib::atomic m_pendding;
129-
exlib::atomic m_in_use;
124+
exlib::atomic m_has_timer;
130125

131126
int64_t m_fid;
132127

fibjs/include/v8_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace fibjs {
1212

13+
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
14+
1315
struct V8FrameInfo {
1416
void* entry_fp;
1517
void* handle;

fibjs/src/base/Runtime.cpp

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ Isolate::rt_base::rt_base(Isolate* cur)
6666

6767
fb->m_c_entry_fp_ = _fi.entry_fp;
6868
fb->m_handler_ = _fi.handle;
69-
70-
m_isolate->m_in_use = 0;
7169
}
7270

7371
Isolate::rt_base::~rt_base()
7472
{
75-
m_isolate->m_in_use = 1;
7673
}
7774

7875
static void fb_GCCallback(v8::Isolate* js_isolate, v8::GCType type, v8::GCCallbackFlags flags)
@@ -191,72 +188,20 @@ void Isolate::start_profiler()
191188
m_pendding.dec();
192189
}
193190
}
194-
195-
class CallbackData : public obj_base {
196-
public:
197-
CallbackData(Isolate* isolate, v8::InterruptCallback callback, void* data)
198-
: m_isolate(isolate)
199-
, m_callback(callback)
200-
, m_data(data)
201-
{
202-
}
203-
204-
void invoke()
205-
{
206-
if (m_invoked.CompareAndSwap(0, 1) == 0)
207-
m_callback(m_isolate->m_isolate, m_data);
208-
}
209-
210-
public:
211-
Isolate* m_isolate;
212-
v8::InterruptCallback m_callback;
213-
void* m_data;
214-
exlib::atomic m_invoked;
215-
};
216-
217-
static result_t js_timer(CallbackData* cd)
191+
void InvokeApiInterruptCallbacks(v8::Isolate* isolate);
192+
static result_t js_timer(Isolate* isolate)
218193
{
219194
JSFiber::scope s;
220-
cd->invoke();
221-
cd->Unref();
195+
isolate->m_has_timer = 0;
196+
InvokeApiInterruptCallbacks(isolate->m_isolate);
222197
return 0;
223198
}
224199

225-
static void _InterruptCallback(v8::Isolate* isolate, void* data)
226-
{
227-
CallbackData* cd = (CallbackData*)data;
228-
cd->invoke();
229-
cd->Unref();
230-
}
231-
232200
void Isolate::RequestInterrupt(v8::InterruptCallback callback, void* data)
233201
{
234-
CallbackData* cd = new CallbackData(this, callback, data);
235-
cd->Ref();
236-
237-
if (IsInUse()) {
238-
cd->Ref();
239-
m_isolate->RequestInterrupt(_InterruptCallback, cd);
240-
241-
exlib::OSThread::sleep(1);
242-
243-
if (!cd->m_invoked) {
244-
cd->Ref();
245-
syncCall(this, js_timer, cd);
246-
}
247-
} else {
248-
cd->Ref();
249-
syncCall(this, js_timer, cd);
250-
251-
exlib::OSThread::sleep(1);
252-
253-
if (IsInUse() && !cd->m_invoked) {
254-
cd->Ref();
255-
m_isolate->RequestInterrupt(_InterruptCallback, cd);
256-
}
257-
}
258-
259-
cd->Unref();
202+
m_isolate->RequestInterrupt(callback, data);
203+
if (m_has_timer.CompareAndSwap(0, 1) == 0)
204+
syncCall(this, js_timer, this);
260205
}
261206

262207
} /* namespace fibjs */

fibjs/src/base/v8_api.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
namespace fibjs {
2424

25+
void InvokeApiInterruptCallbacks(v8::Isolate* isolate)
26+
{
27+
v8::internal::Isolate* v8_isolate = (v8::internal::Isolate*)isolate;
28+
v8_isolate->InvokeApiInterruptCallbacks();
29+
}
30+
2531
V8FrameInfo save_fi(v8::Isolate* isolate)
2632
{
2733
v8::internal::Isolate* v8_isolate = (v8::internal::Isolate*)isolate;

fibjs/src/coroutine/Fiber.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ void JSFiber::fiber_proc(void* p)
6868
v8::HandleScope handle_scope(isolate->m_isolate);
6969
AsyncEvent* ae = (AsyncEvent*)isolate->m_jobs.getHead();
7070

71-
isolate->m_in_use = 1;
7271
hr = ae->js_invoke();
73-
isolate->m_in_use = 0;
7472
}
7573

7674
if (isolate->m_pendding.dec() == 0)

vender

0 commit comments

Comments
 (0)