mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
Merge branch 'magistere-main-patch-71903' into 'main'
Fix excessive CPU usage on Windows See merge request famedly/fluffychat!482
This commit is contained in:
commit
bb0f9e92a3
@ -9,37 +9,10 @@ RunLoop::RunLoop() {}
|
||||
RunLoop::~RunLoop() {}
|
||||
|
||||
void RunLoop::Run() {
|
||||
bool keep_running = true;
|
||||
TimePoint next_flutter_event_time = TimePoint::clock::now();
|
||||
while (keep_running) {
|
||||
std::chrono::nanoseconds wait_duration =
|
||||
std::max(std::chrono::nanoseconds(0),
|
||||
next_flutter_event_time - TimePoint::clock::now());
|
||||
::MsgWaitForMultipleObjects(
|
||||
0, nullptr, FALSE, static_cast<DWORD>(wait_duration.count() / 1000),
|
||||
QS_ALLINPUT);
|
||||
bool processed_events = false;
|
||||
MSG message;
|
||||
// All pending Windows messages must be processed; MsgWaitForMultipleObjects
|
||||
// won't return again for items left in the queue after PeekMessage.
|
||||
while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
|
||||
processed_events = true;
|
||||
if (message.message == WM_QUIT) {
|
||||
keep_running = false;
|
||||
break;
|
||||
}
|
||||
::TranslateMessage(&message);
|
||||
::DispatchMessage(&message);
|
||||
// Allow Flutter to process messages each time a Windows message is
|
||||
// processed, to prevent starvation.
|
||||
next_flutter_event_time =
|
||||
std::min(next_flutter_event_time, ProcessFlutterMessages());
|
||||
}
|
||||
// If the PeekMessage loop didn't run, process Flutter messages.
|
||||
if (!processed_events) {
|
||||
next_flutter_event_time =
|
||||
std::min(next_flutter_event_time, ProcessFlutterMessages());
|
||||
}
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user