2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/utils/port/detail/EventFdWindows.h"
|
|
|
|
|
|
|
|
char disable_linker_warning_about_empty_file_event_fd_windows_cpp TD_UNUSED;
|
|
|
|
|
|
|
|
#ifdef TD_EVENTFD_WINDOWS
|
|
|
|
|
2018-09-10 03:08:15 +02:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
void EventFdWindows::init() {
|
2018-09-11 19:31:53 +02:00
|
|
|
auto handle = CreateEventW(nullptr, true, false, nullptr);
|
|
|
|
if (handle == nullptr) {
|
|
|
|
auto error = OS_ERROR("CreateEventW failed");
|
|
|
|
LOG(FATAL) << error;
|
|
|
|
}
|
|
|
|
event_ = NativeFd(handle);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EventFdWindows::empty() {
|
2018-08-13 19:15:09 +02:00
|
|
|
return !event_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventFdWindows::close() {
|
2018-08-13 19:15:09 +02:00
|
|
|
event_.close();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status EventFdWindows::get_pending_error() {
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2018-08-13 19:15:09 +02:00
|
|
|
PollableFdInfo &EventFdWindows::get_poll_info() {
|
|
|
|
UNREACHABLE();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventFdWindows::release() {
|
2018-09-11 19:31:53 +02:00
|
|
|
if (SetEvent(event_.fd()) == 0) {
|
|
|
|
auto error = OS_ERROR("SetEvent failed");
|
|
|
|
LOG(FATAL) << error;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventFdWindows::acquire() {
|
2018-09-11 19:31:53 +02:00
|
|
|
if (ResetEvent(event_.fd()) == 0) {
|
|
|
|
auto error = OS_ERROR("ResetEvent failed");
|
|
|
|
LOG(FATAL) << error;
|
|
|
|
}
|
2018-08-13 19:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventFdWindows::wait(int timeout_ms) {
|
2018-09-11 15:27:20 +02:00
|
|
|
WaitForSingleObject(event_.fd(), timeout_ms);
|
2018-09-11 19:31:53 +02:00
|
|
|
if (ResetEvent(event_.fd()) == 0) {
|
|
|
|
auto error = OS_ERROR("ResetEvent failed");
|
|
|
|
LOG(FATAL) << error;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace td
|
|
|
|
|
|
|
|
#endif
|