[flang-commits] [flang] [flang] Remove C++ runtime dependency from Sleep extension (PR #84911)
David Truby via flang-commits
flang-commits at lists.llvm.org
Tue Mar 12 07:47:39 PDT 2024
https://github.com/DavidTruby updated https://github.com/llvm/llvm-project/pull/84911
>From 4e988fa105539a419af469741cd86b57e8ef59ec Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Tue, 12 Mar 2024 13:34:58 +0000
Subject: [PATCH 1/2] [flang] Remove C++ runtime dependency from Sleep
extension
The Sleep extension currently has a potential dependency on the C++ runtime. I
run into this dependency using libc++ on Linux. This patch uses the POSIX
`sleep` function or the Windows `Sleep` function instead to avoid this
dependency.
---
flang/runtime/extensions.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index 3ac98000335d7d..fb11e792f613f5 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -135,7 +135,11 @@ void RTNAME(Sleep)(std::int64_t seconds) {
if (seconds < 1) {
return;
}
- std::this_thread::sleep_for(std::chrono::seconds(seconds));
+#if _WIN32
+ Sleep(seconds * 1000);
+#else
+ sleep(seconds);
+#endif
}
} // namespace Fortran::runtime
>From 2856f66c09d8a5464faa8e84191eb255774bbf61 Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Tue, 12 Mar 2024 14:47:16 +0000
Subject: [PATCH 2/2] Add missing include for Win32
---
flang/runtime/extensions.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index fb11e792f613f5..2b4f9b30ebb170 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -22,6 +22,8 @@
#include <thread>
#ifdef _WIN32
+#include <synchapi.h>
+
inline void CtimeBuffer(char *buffer, size_t bufsize, const time_t cur_time,
Fortran::runtime::Terminator terminator) {
int error{ctime_s(buffer, bufsize, &cur_time)};
More information about the flang-commits
mailing list