1 // Copyright (c) 2012 The Chromium 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.
5 // This provides a wrapper around system calls which may be interrupted by a
6 // signal and return EINTR. See man 7 signal.
7 // To prevent long-lasting loops (which would likely be a bug, such as a signal
8 // that should be masked) to go unnoticed, there is a limit after which the
9 // caller will nonetheless see an EINTR in Debug builds.
11 // On Windows, this wrapper macro does nothing.
13 // Don't wrap close calls in HANDLE_EINTR. Use IGNORE_EINTR if the return
14 // value of close is significant. See http://crbug.com/269623.
16 #ifndef BASE_POSIX_EINTR_WRAPPER_H_
17 #define BASE_POSIX_EINTR_WRAPPER_H_
19 #include "build/build_config.h"
27 #define HANDLE_EINTR(x) ({ \
28 decltype(x) eintr_wrapper_result; \
30 eintr_wrapper_result = (x); \
31 } while (eintr_wrapper_result == -1 && errno == EINTR); \
32 eintr_wrapper_result; \
37 #define HANDLE_EINTR(x) ({ \
38 int eintr_wrapper_counter = 0; \
39 decltype(x) eintr_wrapper_result; \
41 eintr_wrapper_result = (x); \
42 } while (eintr_wrapper_result == -1 && errno == EINTR && \
43 eintr_wrapper_counter++ < 100); \
44 eintr_wrapper_result; \
49 #define IGNORE_EINTR(x) ({ \
50 decltype(x) eintr_wrapper_result; \
52 eintr_wrapper_result = (x); \
53 if (eintr_wrapper_result == -1 && errno == EINTR) { \
54 eintr_wrapper_result = 0; \
57 eintr_wrapper_result; \
62 #define HANDLE_EINTR(x) (x)
63 #define IGNORE_EINTR(x) (x)
67 #endif // BASE_POSIX_EINTR_WRAPPER_H_