1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP_SUPPORT_IBM_NANOSLEEP_H 11 #define _LIBCPP_SUPPORT_IBM_NANOSLEEP_H 12 13 #include <unistd.h> 14 nanosleep(const struct timespec * req,struct timespec * rem)15inline int nanosleep(const struct timespec* req, struct timespec* rem) 16 { 17 // The nanosleep() function is not available on z/OS. Therefore, we will call 18 // sleep() to sleep for whole seconds and usleep() to sleep for any remaining 19 // fraction of a second. Any remaining nanoseconds will round up to the next 20 // microsecond. 21 22 useconds_t __micro_sec = (rem->tv_nsec + 999) / 1000; 23 if (__micro_sec > 999999) 24 { 25 ++rem->tv_sec; 26 __micro_sec -= 1000000; 27 } 28 while (rem->tv_sec) 29 rem->tv_sec = sleep(rem->tv_sec); 30 if (__micro_sec) { 31 rem->tv_nsec = __micro_sec * 1000; 32 return usleep(__micro_sec); 33 } 34 rem->tv_nsec = 0; 35 return 0; 36 } 37 38 #endif // _LIBCPP_SUPPORT_IBM_NANOSLEEP_H 39