Flutter Engine
timerfd.h
Go to the documentation of this file.
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_
Definition: ascii_trie.cc:9
int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
Definition: timerfd.cc:21
int timerfd_create(int clockid, int flags)
Definition: timerfd.cc:17
bool TimerDrain(int fd)
Definition: timerfd.cc:54
bool TimerRearm(int fd, fml::TimePoint time_point)
Rearms the timer to expire at the given time point.
Definition: timerfd.cc:36
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66