1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "flutter/fml/platform/win/message_loop_win.h" 6 7 #include "flutter/fml/logging.h" 8 9 namespace fml { 10 MessageLoopWin()11MessageLoopWin::MessageLoopWin() 12 : timer_(CreateWaitableTimer(NULL, FALSE, NULL)) { 13 FML_CHECK(timer_.is_valid()); 14 } 15 16 MessageLoopWin::~MessageLoopWin() = default; 17 Run()18void MessageLoopWin::Run() { 19 running_ = true; 20 21 while (running_) { 22 FML_CHECK(WaitForSingleObject(timer_.get(), INFINITE) == 0); 23 RunExpiredTasksNow(); 24 } 25 } 26 Terminate()27void MessageLoopWin::Terminate() { 28 running_ = false; 29 WakeUp(fml::TimePoint::Now()); 30 } 31 WakeUp(fml::TimePoint time_point)32void MessageLoopWin::WakeUp(fml::TimePoint time_point) { 33 LARGE_INTEGER due_time = {0}; 34 fml::TimePoint now = fml::TimePoint::Now(); 35 if (time_point > now) { 36 due_time.QuadPart = (time_point - now).ToNanoseconds() / -100; 37 } 38 FML_CHECK(SetWaitableTimer(timer_.get(), &due_time, 0, NULL, NULL, FALSE)); 39 } 40 41 } // namespace fml 42