| 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/globals.h" | 8 #include "platform/globals.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 sigset_t old; | 52 sigset_t old; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 | 55 |
| 56 // The definition below is copied from Linux and adapted to avoid lint | 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 | 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. | 58 // separate lines with body in {}s) and to also block signals. |
| 59 #define TEMP_FAILURE_RETRY(expression) \ | 59 #define TEMP_FAILURE_RETRY(expression) \ |
| 60 ({ ThreadSignalBlocker tsb(SIGPROF); \ | 60 ({ \ |
| 61 intptr_t __result; \ | 61 ThreadSignalBlocker tsb(SIGPROF); \ |
| 62 do { \ | 62 intptr_t __result; \ |
| 63 __result = (expression); \ | 63 do { \ |
| 64 } while ((__result == -1L) && (errno == EINTR)); \ | 64 __result = (expression); \ |
| 65 __result; }) | 65 } while ((__result == -1L) && (errno == EINTR)); \ |
| 66 __result; \ |
| 67 }) |
| 66 | 68 |
| 67 // This is a version of TEMP_FAILURE_RETRY which does not use the value | 69 // This is a version of TEMP_FAILURE_RETRY which does not use the value |
| 68 // returned from the expression. | 70 // returned from the expression. |
| 69 #define VOID_TEMP_FAILURE_RETRY(expression) \ | 71 #define VOID_TEMP_FAILURE_RETRY(expression) \ |
| 70 (static_cast<void>(TEMP_FAILURE_RETRY(expression))) | 72 (static_cast<void>(TEMP_FAILURE_RETRY(expression))) |
| 71 | 73 |
| 72 // This macro can be used to insert checks that a call is made, that | 74 // 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. | 75 // was expected to not return EINTR, but did it anyway. |
| 74 #define NO_RETRY_EXPECTED(expression) \ | 76 #define NO_RETRY_EXPECTED(expression) \ |
| 75 ({ intptr_t __result = (expression); \ | 77 ({ \ |
| 76 if (__result == -1L && errno == EINTR) { \ | 78 intptr_t __result = (expression); \ |
| 77 FATAL("Unexpected EINTR errno"); \ | 79 if (__result == -1L && errno == EINTR) { \ |
| 78 } \ | 80 FATAL("Unexpected EINTR errno"); \ |
| 79 __result; }) | 81 } \ |
| 82 __result; \ |
| 83 }) |
| 80 | 84 |
| 81 #define VOID_NO_RETRY_EXPECTED(expression) \ | 85 #define VOID_NO_RETRY_EXPECTED(expression) \ |
| 82 (static_cast<void>(NO_RETRY_EXPECTED(expression))) | 86 (static_cast<void>(NO_RETRY_EXPECTED(expression))) |
| 83 | 87 |
| 84 // Define to check in debug mode, if a signal is currently being blocked. | 88 // Define to check in debug mode, if a signal is currently being blocked. |
| 85 #define CHECK_IS_BLOCKING(signal) \ | 89 #define CHECK_IS_BLOCKING(signal) \ |
| 86 ({ sigset_t signal_mask; \ | 90 ({ \ |
| 87 int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \ | 91 sigset_t signal_mask; \ |
| 88 USE(__r); \ | 92 int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \ |
| 89 ASSERT(__r == 0); \ | 93 USE(__r); \ |
| 90 sigismember(&signal_mask, signal); }) \ | 94 ASSERT(__r == 0); \ |
| 95 sigismember(&signal_mask, signal); \ |
| 96 }) |
| 91 | 97 |
| 92 | 98 |
| 93 // Versions of the above, that does not enter a signal blocking scope. Use only | 99 // Versions of the above, that does not enter a signal blocking scope. Use only |
| 94 // when a signal blocking scope is entered manually. | 100 // when a signal blocking scope is entered manually. |
| 95 #define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ | 101 #define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ |
| 96 ({ intptr_t __result; \ | 102 ({ \ |
| 97 ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \ | 103 intptr_t __result; \ |
| 98 do { \ | 104 ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \ |
| 99 __result = (expression); \ | 105 do { \ |
| 100 } while ((__result == -1L) && (errno == EINTR)); \ | 106 __result = (expression); \ |
| 101 __result; }) | 107 } while ((__result == -1L) && (errno == EINTR)); \ |
| 108 __result; \ |
| 109 }) |
| 102 | 110 |
| 103 #define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ | 111 #define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ |
| 104 (static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) | 112 (static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) |
| 105 | 113 |
| 106 } // namespace dart | 114 } // namespace dart |
| 107 | 115 |
| 108 #endif // RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ | 116 #endif // RUNTIME_PLATFORM_SIGNAL_BLOCKER_H_ |
| OLD | NEW |