Flutter Engine
eintr_wrapper.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_EINTR_WRAPPER_H_
6 #define FLUTTER_FML_EINTR_WRAPPER_H_
7 
8 #include <errno.h>
9 
10 #include "flutter/fml/build_config.h"
11 
12 #if defined(OS_WIN)
13 
14 // Windows has no concept of EINTR.
15 #define FML_HANDLE_EINTR(x) (x)
16 #define FML_IGNORE_EINTR(x) (x)
17 
18 #else
19 
20 #if defined(NDEBUG)
21 
22 #define FML_HANDLE_EINTR(x) \
23  ({ \
24  decltype(x) eintr_wrapper_result; \
25  do { \
26  eintr_wrapper_result = (x); \
27  } while (eintr_wrapper_result == -1 && errno == EINTR); \
28  eintr_wrapper_result; \
29  })
30 
31 #else
32 
33 #define FML_HANDLE_EINTR(x) \
34  ({ \
35  int eintr_wrapper_counter = 0; \
36  decltype(x) eintr_wrapper_result; \
37  do { \
38  eintr_wrapper_result = (x); \
39  } while (eintr_wrapper_result == -1 && errno == EINTR && \
40  eintr_wrapper_counter++ < 100); \
41  eintr_wrapper_result; \
42  })
43 
44 #endif // NDEBUG
45 
46 #define FML_IGNORE_EINTR(x) \
47  ({ \
48  decltype(x) eintr_wrapper_result; \
49  do { \
50  eintr_wrapper_result = (x); \
51  if (eintr_wrapper_result == -1 && errno == EINTR) { \
52  eintr_wrapper_result = 0; \
53  } \
54  } while (0); \
55  eintr_wrapper_result; \
56  })
57 
58 #endif // defined(OS_WIN)
59 
60 #endif // FLUTTER_FML_EINTR_WRAPPER_H_