| 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(FML_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 | #define FML_HANDLE_EINTR(x) \ |
| 21 | ({ \ |
| 22 | decltype(x) eintr_wrapper_result; \ |
| 23 | do { \ |
| 24 | eintr_wrapper_result = (x); \ |
| 25 | } while (eintr_wrapper_result == -1 && errno == EINTR); \ |
| 26 | eintr_wrapper_result; \ |
| 27 | }) |
| 28 | |
| 29 | #define FML_IGNORE_EINTR(x) \ |
| 30 | ({ \ |
| 31 | decltype(x) eintr_wrapper_result; \ |
| 32 | do { \ |
| 33 | eintr_wrapper_result = (x); \ |
| 34 | if (eintr_wrapper_result == -1 && errno == EINTR) { \ |
| 35 | eintr_wrapper_result = 0; \ |
| 36 | } \ |
| 37 | } while (0); \ |
| 38 | eintr_wrapper_result; \ |
| 39 | }) |
| 40 | |
| 41 | #endif // defined(FML_OS_WIN) |
| 42 | |
| 43 | #endif // FLUTTER_FML_EINTR_WRAPPER_H_ |
| 44 | |