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 BIN_SIGNAL_BLOCKER_H_ |
6 #define BIN_SIGNAL_BLOCKER_H_ | 6 #define BIN_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 namespace dart { | 16 namespace dart { |
17 namespace bin { | 17 namespace bin { |
18 | 18 |
19 class ThreadSignalBlocker { | 19 class ThreadSignalBlocker { |
20 public: | 20 public: |
21 explicit ThreadSignalBlocker(int sig) { | 21 explicit ThreadSignalBlocker(int sig) { |
22 sigset_t signal_mask; | 22 sigset_t signal_mask; |
23 sigemptyset(&signal_mask); | 23 sigemptyset(&signal_mask); |
24 sigaddset(&signal_mask, sig); | 24 sigaddset(&signal_mask, sig); |
25 // Add sig to signal mask. | 25 // Add sig to signal mask. |
26 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); | 26 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); |
27 ASSERT(r == 0); | 27 ASSERT(r == 0); |
28 } | 28 } |
29 | 29 |
30 ThreadSignalBlocker(int sigs_count, const int sigs[]) { | |
31 sigset_t signal_mask; | |
32 sigemptyset(&signal_mask); | |
33 for (int i = 0; i < sigs_count; i++) { | |
34 sigaddset(&signal_mask, sigs[i]); | |
35 } | |
36 // Add sig to signal mask. | |
37 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); | |
Søren Gjesse
2013/12/18 08:07:14
You will probably need USE(r) for release mode.
Anders Johnsen
2013/12/18 21:20:29
Done.
| |
38 ASSERT(r == 0); | |
39 } | |
40 | |
30 ~ThreadSignalBlocker() { | 41 ~ThreadSignalBlocker() { |
31 // Restore signal mask. | 42 // Restore signal mask. |
32 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); | 43 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); |
33 ASSERT(r == 0); | 44 ASSERT(r == 0); |
34 } | 45 } |
35 | 46 |
36 private: | 47 private: |
37 sigset_t old; | 48 sigset_t old; |
38 }; | 49 }; |
39 | 50 |
40 | 51 |
41 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | 52 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ |
42 ({ ThreadSignalBlocker tsb(SIGPROF); \ | 53 ({ ThreadSignalBlocker tsb(SIGPROF); \ |
43 int64_t __result; \ | 54 int64_t __result; \ |
44 do { \ | 55 do { \ |
45 __result = static_cast<int64_t>(expression); \ | 56 __result = static_cast<int64_t>(expression); \ |
46 } while (__result == -1L && errno == EINTR); \ | 57 } while (__result == -1L && errno == EINTR); \ |
47 __result; }) | 58 __result; }) |
48 | 59 |
49 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | 60 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ |
50 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression))) | 61 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression))) |
51 | 62 |
52 } // namespace bin | 63 } // namespace bin |
53 } // namespace dart | 64 } // namespace dart |
54 | 65 |
55 #endif // BIN_SIGNAL_BLOCKER_H_ | 66 #endif // BIN_SIGNAL_BLOCKER_H_ |
OLD | NEW |