[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 06:39:33 PDT 2024


https://github.com/DavidTruby created https://github.com/llvm/llvm-project/pull/84911

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.


>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] [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



More information about the flang-commits mailing list