Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: runtime/bin/signal_blocker.h

Issue 119093007: Signal handling, take 2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process_win.cc ('k') | sdk/lib/_internal/lib/io_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "platform/thread.h" 16 #include "platform/thread.h"
17 17
18 namespace dart { 18 namespace dart {
19 namespace bin { 19 namespace bin {
20 20
21 class ThreadSignalBlocker { 21 class ThreadSignalBlocker {
22 public: 22 public:
23 explicit ThreadSignalBlocker(int sig) { 23 explicit ThreadSignalBlocker(int sig) {
24 sigset_t signal_mask; 24 sigset_t signal_mask;
25 sigemptyset(&signal_mask); 25 sigemptyset(&signal_mask);
26 sigaddset(&signal_mask, sig); 26 sigaddset(&signal_mask, sig);
27 // Add sig to signal mask. 27 // Add sig to signal mask.
28 int r = pthread_sigmask(SIG_BLOCK, &signal_mask, &old); 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);
29 ASSERT(r == 0); 42 ASSERT(r == 0);
30 } 43 }
31 44
32 ~ThreadSignalBlocker() { 45 ~ThreadSignalBlocker() {
33 // Restore signal mask. 46 // Restore signal mask.
34 int r = pthread_sigmask(SIG_SETMASK, &old, NULL); 47 int r = pthread_sigmask(SIG_SETMASK, &old, NULL);
48 USE(r);
35 ASSERT(r == 0); 49 ASSERT(r == 0);
36 } 50 }
37 51
38 private: 52 private:
39 sigset_t old; 53 sigset_t old;
40 }; 54 };
41 55
42 56
43 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ 57 #define TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \
44 ({ ThreadSignalBlocker tsb(SIGPROF); \ 58 ({ ThreadSignalBlocker tsb(SIGPROF); \
45 int64_t __result; \ 59 int64_t __result; \
46 do { \ 60 do { \
47 __result = static_cast<int64_t>(expression); \ 61 __result = static_cast<int64_t>(expression); \
48 } while (__result == -1L && errno == EINTR); \ 62 } while (__result == -1L && errno == EINTR); \
49 __result; }) 63 __result; })
50 64
51 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \ 65 #define VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression) \
52 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression))) 66 (static_cast<void>(TEMP_FAILURE_RETRY_BLOCK_SIGNALS(expression)))
53 67
54 } // namespace bin 68 } // namespace bin
55 } // namespace dart 69 } // namespace dart
56 70
57 #endif // BIN_SIGNAL_BLOCKER_H_ 71 #endif // BIN_SIGNAL_BLOCKER_H_
OLDNEW
« no previous file with comments | « runtime/bin/process_win.cc ('k') | sdk/lib/_internal/lib/io_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698