Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bridge/multiple_threading/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ std::unique_ptr<Looper>& Dispatcher::looper(int32_t js_context_id) {
}

// run in the cpp thread
void Dispatcher::NotifyDart(const DartWork* work_ptr, bool is_sync) {
bool Dispatcher::NotifyDart(const DartWork* work_ptr, bool is_sync) {
const intptr_t work_addr = reinterpret_cast<intptr_t>(work_ptr);

Dart_CObject** array = new Dart_CObject*[3];
Expand Down Expand Up @@ -129,12 +129,14 @@ void Dispatcher::NotifyDart(const DartWork* work_ptr, bool is_sync) {
const bool result = Dart_PostCObject_DL(dart_port_, &dart_object);
if (!result) {
delete work_ptr;
return false;
}

delete array[0];
delete array[1];
delete array[2];
delete[] array;
return true;
}

void Dispatcher::FinalizeAllJSThreads(webf::multi_threading::Callback callback) {
Expand Down
8 changes: 6 additions & 2 deletions bridge/multiple_threading/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ class Dispatcher {
DartWork* work_ptr = new DartWork(work);
pending_dart_tasks_.insert(work_ptr);

NotifyDart(work_ptr, true);
bool success = NotifyDart(work_ptr, true);
if (!success) {
pending_dart_tasks_.erase(work_ptr);
return std::invoke(std::forward<Func>(func), true, std::forward<Args>(args)...);
}

looper->is_blocked_ = true;
task->wait();
Expand Down Expand Up @@ -170,7 +174,7 @@ class Dispatcher {
}

private:
void NotifyDart(const DartWork* work_ptr, bool is_sync);
bool NotifyDart(const DartWork* work_ptr, bool is_sync);

void FinalizeAllJSThreads(Callback callback);
void StopAllJSThreads();
Expand Down