OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #ifndef BIN_SIGNAL_BLOCKER_H_ | |
6 #define BIN_SIGNAL_BLOCKER_H_ | |
7 | |
8 #include "platform/globals.h" | |
9 | |
10 #if defined(TARGET_OS_WINDOWS) | |
11 #error Do not include this file on Windows. | |
12 #endif | |
13 | |
14 #include <signal.h> // NOLINT | |
15 | |
16 #include "platform/thread.h" | |
17 | |
18 namespace dart { | |
19 namespace bin { | |
20 | |
21 class ThreadSignalBlocker { | |
22 public: | |
23 explicit ThreadSignalBlocker(int sig) { | |
24 sigset_t signal_mask; | |
25 sigemptyset(&signal_mask); | |
26 sigaddset(&signal_mask, sig); | |
27 // Add sig to signal mask. | |
28 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); | |
29 USE(r); | |
30 ASSERT(r == 0); | |
31 } | |
32 | |
33 ThreadSignalBlocker(int sigs_count, const int sigs[]) { | |
34 sigset_t signal_mask; | |
35 sigemptyset(&signal_mask); | |
36 for (int i = 0; i < sigs_count; i++) { | |
37 sigaddset(&signal_mask, sigs[i]); | |
38 } | |
39 // Add sig to signal mask. | |
40 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); | |
41 USE(r); | |
42 ASSERT(r == 0); | |
43 } | |
44 | |
45 ~ThreadSignalBlocker() { | |
46 // Restore signal mask. | |
47 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); | |
48 USE(r); | |
49 ASSERT(r == 0); | |
50 } | |
51 | |
52 private: | |
53 sigset_t old; | |
54 }; | |
55 | |
56 | |
57 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | |
58 ({ ThreadSignalBlocker tsb(SIGPROF); \ | |
59 intptr_t __result; \ | |
60 do { \ | |
61 __result = (expression); \ | |
62 } while ((__result == -1L) && (errno == EINTR)); \ | |
63 __result; }) | |
64 | |
65 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ | |
66 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression))) | |
67 | |
68 } // namespace bin | |
69 } // namespace dart | |
70 | |
71 #endif // BIN_SIGNAL_BLOCKER_H_ | |
OLD | NEW |