diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support --- a/libcxx/include/__threading_support +++ b/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() is not available on z/OS. Therefore, + // we will call sleep() to sleep for a whole seconds + // and usleep() to sleep for a fraction of a second. + // Any remaining nano seconds will round up to the next micro second. + + useconds_t __micro_sec = (__ts.tv_nsec + 999) / 1000; + if (__micro_sec > 999999) + { + __ts.tv_sec++; + __micro_sec = 0; + } + 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 diff --git a/libcxx/src/filesystem/filesystem_common.h b/libcxx/src/filesystem/filesystem_common.h --- a/libcxx/src/filesystem/filesystem_common.h +++ b/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 = { + ts.tv_sec, +#if defined(__MVS__) + {}, +#endif + 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;