OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_SIGNAL_BLOCKER_H_ | 5 #ifndef PLATFORM_SIGNAL_BLOCKER_H_ |
6 #define BIN_SIGNAL_BLOCKER_H_ | 6 #define PLATFORM_SIGNAL_BLOCKER_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 #if defined(TARGET_OS_WINDOWS) | 10 #if defined(TARGET_OS_WINDOWS) |
11 #error Do not include this file on Windows. | 11 #error Do not include this file on Windows. |
12 #endif | 12 #endif |
13 | 13 |
14 #include <signal.h> // NOLINT | 14 #include <signal.h> // NOLINT |
15 | 15 |
16 #include "platform/thread.h" | 16 #include "platform/thread.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 namespace bin { | |
20 | 19 |
21 class ThreadSignalBlocker { | 20 class ThreadSignalBlocker { |
22 public: | 21 public: |
23 explicit ThreadSignalBlocker(int sig) { | 22 explicit ThreadSignalBlocker(int sig) { |
24 sigset_t signal_mask; | 23 sigset_t signal_mask; |
25 sigemptyset(&signal_mask); | 24 sigemptyset(&signal_mask); |
26 sigaddset(&signal_mask, sig); | 25 sigaddset(&signal_mask, sig); |
27 // Add sig to signal mask. | 26 // Add sig to signal mask. |
28 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); | 27 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); |
29 USE(r); | 28 USE(r); |
(...skipping 17 matching lines...) Expand all Loading... |
47 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); | 46 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); |
48 USE(r); | 47 USE(r); |
49 ASSERT(r == 0); | 48 ASSERT(r == 0); |
50 } | 49 } |
51 | 50 |
52 private: | 51 private: |
53 sigset_t old; | 52 sigset_t old; |
54 }; | 53 }; |
55 | 54 |
56 | 55 |
57 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | 56 // The definition below is copied from Linux and adapted to avoid lint |
| 57 // errors (type long int changed to intptr_t and do/while split on |
| 58 // separate lines with body in {}s) and to also block signals. |
| 59 #define TEMP_FAILURE_RETRY(expression) \ |
58 ({ ThreadSignalBlocker tsb(SIGPROF); \ | 60 ({ ThreadSignalBlocker tsb(SIGPROF); \ |
59 intptr_t __result; \ | 61 intptr_t __result; \ |
60 do { \ | 62 do { \ |
61 __result = (expression); \ | 63 __result = (expression); \ |
62 } while ((__result == -1L) && (errno == EINTR)); \ | 64 } while ((__result == -1L) && (errno == EINTR)); \ |
63 __result; }) | 65 __result; }) |
64 | 66 |
65 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | 67 // This is a version of TEMP_FAILURE_RETRY which does not use the value |
66 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression))) | 68 // returned from the expression. |
| 69 #define VOID_TEMP_FAILURE_RETRY(expression) \ |
| 70 (static_cast<void>(TEMP_FAILURE_RETRY(expression))) |
67 | 71 |
68 } // namespace bin | 72 // This macro can be used to insert checks that a call is made, that |
| 73 // was expected to not return EINTR, but did it anyway. |
| 74 #define NO_RETRY_EXPECTED(expression) \ |
| 75 ({ intptr_t __result = (expression); \ |
| 76 ASSERT(__result != -1L || errno != EINTR); \ |
| 77 __result; }) |
| 78 |
| 79 #define VOID_NO_RETRY_EXPECTED(expression) \ |
| 80 (static_cast<void>(NO_RETRY_EXPECTED(expression))) |
| 81 |
69 } // namespace dart | 82 } // namespace dart |
70 | 83 |
71 #endif // BIN_SIGNAL_BLOCKER_H_ | 84 #endif // PLATFORM_SIGNAL_BLOCKER_H_ |
OLD | NEW |