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 #ifndef FLUTTER_FML_PLATFORM_LINUX_TIMER_FD_H_ 6 #define FLUTTER_FML_PLATFORM_LINUX_TIMER_FD_H_ 7 8 #include "flutter/fml/time/time_point.h" 9 10 // clang-format off 11 #if __has_include(<sys/timerfd.h>) && \ 12 (!defined(__ANDROID_API__) || __ANDROID_API__ >= 19) 13 // sys/timerfd.h is always present in Android NDK due to unified headers, 14 // but timerfd functions are only available on API 19 or later. 15 // clang-format on 16 17 #include <sys/timerfd.h> 18 19 #define FML_TIMERFD_AVAILABLE 1 20 21 #else // __has_include(<sys/timerfd.h>) 22 23 #define FML_TIMERFD_AVAILABLE 0 24 25 #include <sys/types.h> 26 // Must come after sys/types 27 #include <linux/time.h> 28 29 #define TFD_TIMER_ABSTIME (1 << 0) 30 #define TFD_TIMER_CANCEL_ON_SET (1 << 1) 31 32 #define TFD_CLOEXEC O_CLOEXEC 33 #define TFD_NONBLOCK O_NONBLOCK 34 35 int timerfd_create(int clockid, int flags); 36 37 int timerfd_settime(int ufc, 38 int flags, 39 const struct itimerspec* utmr, 40 struct itimerspec* otmr); 41 42 #endif // __has_include(<sys/timerfd.h>) 43 44 namespace fml { 45 46 /// Rearms the timer to expire at the given time point. 47 bool TimerRearm(int fd, fml::TimePoint time_point); 48 49 /// Drains the timer FD and returns true if it has expired. This may be false in 50 /// case the timer read is non-blocking and this routine was called before the 51 /// timer expiry. 52 bool TimerDrain(int fd); 53 54 } // namespace fml 55 56 #endif // FLUTTER_FML_PLATFORM_LINUX_TIMER_FD_H_ 57