flutter_flutter/fml/platform/win/message_loop_win.cc
Michael Goderbauer 772a0db5e4 Partially port FML to Windows. (#3562)
* Partially port FML to Windows.

* Adds a message loop impl for Windows
* Ports `thread.cc` to Windows

All FML unittests are now passing on Windows.

FML as a whole does not compile on windows yet because `mapping.cc` imports `sys/mman.h`, which is not available on Windows and the replacement API for memory-mapped files is very different on Windows, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366556%28v=vs.85%29.aspx.

* update licenses

* review comments
2017-04-04 12:48:11 -07:00

40 lines
1000 B
C++

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/platform/win/message_loop_win.h"
namespace fml {
MessageLoopWin::MessageLoopWin()
: timer_(CreateWaitableTimer(NULL, FALSE, NULL)) {
FTL_CHECK(timer_.is_valid());
}
MessageLoopWin::~MessageLoopWin() = default;
void MessageLoopWin::Run() {
running_ = true;
while (running_) {
FTL_CHECK(WaitForSingleObject(timer_.get(), INFINITE) == 0);
RunExpiredTasksNow();
}
}
void MessageLoopWin::Terminate() {
running_ = false;
WakeUp(ftl::TimePoint::Now());
}
void MessageLoopWin::WakeUp(ftl::TimePoint time_point) {
LARGE_INTEGER due_time = {0};
ftl::TimePoint now = ftl::TimePoint::Now();
if (time_point > now) {
due_time.QuadPart = (time_point - now).ToNanoseconds() / -100;
}
FTL_CHECK(SetWaitableTimer(timer_.get(), &due_time, 0, NULL, NULL, FALSE));
}
} // namespace fml