| 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 RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 5 #ifndef RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 
| 6 #define RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 6 #define RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 
| 7 | 7 | 
|  | 8 #include "platform/assert.h" | 
| 8 #include "platform/globals.h" | 9 #include "platform/globals.h" | 
| 9 #include "platform/assert.h" |  | 
| 10 | 10 | 
| 11 #if defined(HOST_OS_WINDOWS) | 11 #if defined(HOST_OS_WINDOWS) | 
| 12 #error Do not include this file on Windows. | 12 #error Do not include this file on Windows. | 
| 13 #endif | 13 #endif | 
| 14 | 14 | 
| 15 #include <pthread.h> | 15 #include <pthread.h> | 
| 16 #include <signal.h>  // NOLINT | 16 #include <signal.h>  // NOLINT | 
| 17 | 17 | 
| 18 namespace dart { | 18 namespace dart { | 
| 19 | 19 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 45     // Restore signal mask. | 45     // Restore signal mask. | 
| 46     int r = pthread_sigmask(SIG_SETMASK, &old, NULL); | 46     int r = pthread_sigmask(SIG_SETMASK, &old, NULL); | 
| 47     USE(r); | 47     USE(r); | 
| 48     ASSERT(r == 0); | 48     ASSERT(r == 0); | 
| 49   } | 49   } | 
| 50 | 50 | 
| 51  private: | 51  private: | 
| 52   sigset_t old; | 52   sigset_t old; | 
| 53 }; | 53 }; | 
| 54 | 54 | 
| 55 |  | 
| 56 // The definition below is copied from Linux and adapted to avoid lint | 55 // 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 | 56 // 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. | 57 // separate lines with body in {}s) and to also block signals. | 
| 59 #define TEMP_FAILURE_RETRY(expression)                                         \ | 58 #define TEMP_FAILURE_RETRY(expression)                                         \ | 
| 60   ({                                                                           \ | 59   ({                                                                           \ | 
| 61     ThreadSignalBlocker tsb(SIGPROF);                                          \ | 60     ThreadSignalBlocker tsb(SIGPROF);                                          \ | 
| 62     intptr_t __result;                                                         \ | 61     intptr_t __result;                                                         \ | 
| 63     do {                                                                       \ | 62     do {                                                                       \ | 
| 64       __result = (expression);                                                 \ | 63       __result = (expression);                                                 \ | 
| 65     } while ((__result == -1L) && (errno == EINTR));                           \ | 64     } while ((__result == -1L) && (errno == EINTR));                           \ | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 88 // Define to check in debug mode, if a signal is currently being blocked. | 87 // Define to check in debug mode, if a signal is currently being blocked. | 
| 89 #define CHECK_IS_BLOCKING(signal)                                              \ | 88 #define CHECK_IS_BLOCKING(signal)                                              \ | 
| 90   ({                                                                           \ | 89   ({                                                                           \ | 
| 91     sigset_t signal_mask;                                                      \ | 90     sigset_t signal_mask;                                                      \ | 
| 92     int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask);                  \ | 91     int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask);                  \ | 
| 93     USE(__r);                                                                  \ | 92     USE(__r);                                                                  \ | 
| 94     ASSERT(__r == 0);                                                          \ | 93     ASSERT(__r == 0);                                                          \ | 
| 95     sigismember(&signal_mask, signal);                                         \ | 94     sigismember(&signal_mask, signal);                                         \ | 
| 96   }) | 95   }) | 
| 97 | 96 | 
| 98 |  | 
| 99 // Versions of the above, that does not enter a signal blocking scope. Use only | 97 // Versions of the above, that does not enter a signal blocking scope. Use only | 
| 100 // when a signal blocking scope is entered manually. | 98 // when a signal blocking scope is entered manually. | 
| 101 #define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)                       \ | 99 #define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)                       \ | 
| 102   ({                                                                           \ | 100   ({                                                                           \ | 
| 103     intptr_t __result;                                                         \ | 101     intptr_t __result;                                                         \ | 
| 104     ASSERT(CHECK_IS_BLOCKING(SIGPROF));                                        \ | 102     ASSERT(CHECK_IS_BLOCKING(SIGPROF));                                        \ | 
| 105     do {                                                                       \ | 103     do {                                                                       \ | 
| 106       __result = (expression);                                                 \ | 104       __result = (expression);                                                 \ | 
| 107     } while ((__result == -1L) && (errno == EINTR));                           \ | 105     } while ((__result == -1L) && (errno == EINTR));                           \ | 
| 108     __result;                                                                  \ | 106     __result;                                                                  \ | 
| 109   }) | 107   }) | 
| 110 | 108 | 
| 111 #define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)                  \ | 109 #define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)                  \ | 
| 112   (static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) | 110   (static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) | 
| 113 | 111 | 
| 114 }  // namespace dart | 112 }  // namespace dart | 
| 115 | 113 | 
| 116 #endif  // RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 114 #endif  // RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 
| OLD | NEW | 
|---|