Index: libcxx/include/__threading_support =================================================================== --- libcxx/include/__threading_support +++ libcxx/include/__threading_support @@ -15,6 +15,10 @@ #include #include +#ifdef __MVS__ +#include +#endif + #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #pragma GCC system_header #endif @@ -532,7 +536,25 @@ void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) { __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns); +#if defined(__MVS__) + // The nanosleep() function is not available on z/OS. Therefore, we will call + // sleep() to sleep for whole seconds and usleep() to sleep for any remaining + // fraction of a second. Any remaining nanoseconds will round up to the next + // microsecond. + + useconds_t __micro_sec = (__ts.tv_nsec + 999) / 1000; + if (__micro_sec > 999999) + { + ++__ts.tv_sec; + __micro_sec -= 1000000; + } + while (__ts.tv_sec) + __ts.tv_sec = sleep(__ts.tv_sec); + if (__micro_sec) + usleep(__micro_sec); +#else while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR); +#endif } // Thread local storage Index: libcxx/src/filesystem/filesystem_common.h =================================================================== --- libcxx/src/filesystem/filesystem_common.h +++ libcxx/src/filesystem/filesystem_common.h @@ -198,6 +198,7 @@ using chrono::duration_cast; using TimeSpec = struct ::timespec; +using TimeVal = struct ::timeval; using StatT = struct ::stat; template const& TS, - error_code& ec) { +TimeVal make_timeval(TimeSpec const& ts) { using namespace chrono; auto Convert = [](long nsec) { - using int_type = decltype(std::declval< ::timeval>().tv_usec); + using int_type = decltype(std::declval().tv_usec); auto dur = duration_cast(nanoseconds(nsec)).count(); return static_cast(dur); }; - struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)}, - {TS[1].tv_sec, Convert(TS[1].tv_nsec)}}; + TimeVal TV = {}; + TV.tv_sec = ts.tv_sec; + TV.tv_usec = Convert(ts.tv_nsec); + return TV; +} + +// allow the utimes implementation to compile even it we're not going +// to use it. + +bool posix_utimes(const path& p, std::array const& TS, + error_code& ec) { + TimeVal ConvertedTS[2] = {make_timeval(TS[0]), make_timeval(TS[1])}; if (::utimes(p.c_str(), ConvertedTS) == -1) { ec = capture_errno(); return true;