1 /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef XLA_RUNTIME_DEFAULT_MEMORY_MAPPER_H_ 17 #define XLA_RUNTIME_DEFAULT_MEMORY_MAPPER_H_ 18 19 #include <errno.h> 20 21 namespace xla { 22 namespace runtime { 23 24 // Some syscalls can be interrupted by a signal handler; retry if that happens. 25 template <typename FunctionType> RetryOnEINTR(FunctionType func,decltype (func ())failure_value)26static auto RetryOnEINTR(FunctionType func, decltype(func()) failure_value) { 27 using ReturnType = decltype(func()); 28 ReturnType ret; 29 do { 30 ret = func(); 31 } while (ret == failure_value && errno == EINTR); 32 return ret; 33 } 34 35 } // namespace runtime 36 } // namespace xla 37 38 #endif // XLA_RUNTIME_DEFAULT_MEMORY_MAPPER_H_ 39