[flang-commits] [flang] 227fe1c - [flang] Remove C++ runtime dependency from Sleep extension (#84911)
via flang-commits
flang-commits at lists.llvm.org
Tue May 7 06:27:43 PDT 2024
Author: David Truby
Date: 2024-05-07T14:27:39+01:00
New Revision: 227fe1c1995dea1850483449e8510db2726bcbee
URL: https://github.com/llvm/llvm-project/commit/227fe1c1995dea1850483449e8510db2726bcbee
DIFF: https://github.com/llvm/llvm-project/commit/227fe1c1995dea1850483449e8510db2726bcbee.diff
LOG: [flang] Remove C++ runtime dependency from Sleep extension (#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.
Added:
Modified:
flang/runtime/extensions.cpp
Removed:
################################################################################
diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index 4b110cc10c840..be3833db88b07 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -23,6 +23,12 @@
#include <thread>
#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include <windows.h>
+
+#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)};
@@ -136,7 +142,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
}
// TODO: not supported on Windows
More information about the flang-commits
mailing list