[libcxx-commits] [PATCH] D87940: [SystemZ][ZOS] Porting the time functions within libc++ to z/OS
Zbigniew Sarbinowski via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 9 13:21:33 PDT 2020
zibi updated this revision to Diff 297319.
zibi added a comment.
Removing confusing comment is the only delta.
@ldionne There are plans to have an external buildbot setup on z/OS. I’ll update with more details after discussing with the people trying to figure out the logistics.
As for the `nanosleep()` we would like to keep it upstream it should not be a burden since it's consolidated in one location and clearly guarded for z/OS only. The `nanosleep()` is on our list to implement downstream so the fact we are upstreaming will not minimize our effort to make that function available as part of OS.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87940/new/
https://reviews.llvm.org/D87940
Files:
libcxx/include/__threading_support
libcxx/src/filesystem/filesystem_common.h
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 <class FileTimeT, class TimeT,
@@ -382,24 +383,36 @@
#if defined(__APPLE__)
TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }
TimeSpec extract_atime(StatT const& st) { return st.st_atimespec; }
+#elif defined(__MVS__)
+TimeSpec extract_mtime(StatT const& st) {
+ TimeSpec TS = {st.st_mtime, 0};
+ return TS;
+}
+TimeSpec extract_atime(StatT const& st) {
+ TimeSpec TS = {st.st_atime, 0};
+ return TS;
+}
#else
TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
#endif
-// allow the utimes implementation to compile even it we're not going
-// to use it.
-
-bool posix_utimes(const path& p, std::array<TimeSpec, 2> 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<TimeVal>().tv_usec);
auto dur = duration_cast<microseconds>(nanoseconds(nsec)).count();
return static_cast<int_type>(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;
+}
+
+bool posix_utimes(const path& p, std::array<TimeSpec, 2> 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;
Index: libcxx/include/__threading_support
===================================================================
--- libcxx/include/__threading_support
+++ libcxx/include/__threading_support
@@ -15,6 +15,10 @@
#include <iosfwd>
#include <errno.h>
+#ifdef __MVS__
+#include <unistd.h>
+#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)
+ while (usleep(__micro_sec) == -1 && errno == EINTR);
+#else
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
+#endif
}
// Thread local storage
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87940.297319.patch
Type: text/x-patch
Size: 3263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201009/06b7bb58/attachment.bin>
More information about the libcxx-commits
mailing list