Adding owners for third_party
[chromium-blink-merge.git] / base / posix / eintr_wrapper.h
blob8e26752337066162e14f0c65a1a06f41985d619f
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 #ifndef BASE_POSIX_EINTR_WRAPPER_H_
14 #define BASE_POSIX_EINTR_WRAPPER_H_
16 #include "build/build_config.h"
18 #if defined(OS_POSIX)
20 #include <errno.h>
22 #if defined(NDEBUG)
23 #define HANDLE_EINTR(x) ({ \
24 typeof(x) eintr_wrapper_result; \
25 do { \
26 eintr_wrapper_result = (x); \
27 } while (eintr_wrapper_result == -1 && errno == EINTR); \
28 eintr_wrapper_result; \
31 #else
33 #define HANDLE_EINTR(x) ({ \
34 int eintr_wrapper_counter = 0; \
35 typeof(x) eintr_wrapper_result; \
36 do { \
37 eintr_wrapper_result = (x); \
38 } while (eintr_wrapper_result == -1 && errno == EINTR && \
39 eintr_wrapper_counter++ < 100); \
40 eintr_wrapper_result; \
43 #endif // NDEBUG
45 #else
47 #define HANDLE_EINTR(x) (x)
49 #endif // OS_POSIX
51 #endif // BASE_POSIX_EINTR_WRAPPER_H_