Skip to content

Commit

Permalink
Fix race condition in renderer message loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Oct 22, 2020
1 parent 62f83a7 commit 17d0a01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/message_loop/message_pump_uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ void MessagePumpUV::Run(Delegate* delegate) {
continue;
}

if (event_.IsSignaled()) {
//there is a chance that wake_event_ got processed in uv loop
//run above. then the next wait is stalled.
event_.Reset();
g_msg_pump_did_work_fn(&ctx);
continue;
}
if (next_work_info.delayed_run_time.is_max()) {
// (*node::g_nw_uv_run)(loop, UV_RUN_ONCE);
g_msg_pump_need_work_fn(&ctx);
Expand All @@ -123,6 +130,7 @@ void MessagePumpUV::Run(Delegate* delegate) {
// uv_timer_stop(&delay_timer);
g_msg_pump_delay_work_fn(&ctx, delay.InMilliseconds());
}
event_.Reset();
// Since event_ is auto-reset, we don't need to do anything special here
// other than service each delegate method.
}
Expand Down Expand Up @@ -161,6 +169,7 @@ void MessagePumpUV::ScheduleWork() {
// #else
// uv_async_send(wakeup_event_);
// #endif
event_.Signal();
g_msg_pump_sched_work_fn(wakeup_event_);
}

Expand Down
2 changes: 2 additions & 0 deletions base/message_loop/message_pump_uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/message_loop/message_pump.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "base/synchronization/waitable_event.h"

#include <vector>

Expand Down Expand Up @@ -39,6 +40,7 @@ class BASE_EXPORT MessagePumpUV : public MessagePump {
// Handle to wake up loop.
std::vector<void*> wakeup_events_;
void* wakeup_event_;
WaitableEvent event_;

TimeTicks delayed_work_time_;

Expand Down

0 comments on commit 17d0a01

Please sign in to comment.