Skip to content

Commit 864c317

Browse files
committed
fix build issue by making _FortranAGetMainThreadId() a runtime routine
1 parent a1ce77b commit 864c317

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

flang-rt/lib/runtime/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <cstdio>
1414
#include <cstdlib>
1515
#include <thread>
16-
std::thread::id main_thread_id = std::this_thread::get_id();
17-
extern "C" std::thread::id get_main_thread_id() { return main_thread_id; }
1816

1917
static void ConfigureFloatingPoint() {
2018
#ifdef feclearexcept // a macro in some environments; omit std::
@@ -29,7 +27,10 @@ static void ConfigureFloatingPoint() {
2927
#endif
3028
}
3129

30+
std::thread::id _main_thread_id = std::this_thread::get_id();
3231
extern "C" {
32+
std::thread::id RTNAME(GetMainThreadId)() { return _main_thread_id; }
33+
3334
void RTNAME(ProgramStart)(int argc, const char *argv[], const char *envp[],
3435
const EnvironmentDefaultList *envDefaults) {
3536
std::atexit(Fortran::runtime::NotifyOtherImagesOfNormalEnd);

flang-rt/lib/runtime/stop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#include "flang-rt/runtime/file.h"
1414
#include "flang-rt/runtime/io-error.h"
1515
#include "flang-rt/runtime/terminator.h"
16+
#include "flang/Runtime/main.h"
1617
#include <cfenv>
1718
#include <cstdio>
1819
#include <cstdlib>
1920
#include <thread>
20-
std::thread::id get_main_thread_id();
2121

2222
#ifdef HAVE_BACKTRACE
2323
#include BACKTRACE_HEADER
@@ -81,7 +81,7 @@ static void CloseAllExternalUnits(const char *why) {
8181
std::fputc('\n', stderr);
8282
DescribeIEEESignaledExceptions();
8383
}
84-
if (get_main_thread_id() != std::this_thread::get_id())
84+
if (RTNAME(GetMainThreadId)() != std::this_thread::get_id())
8585
std::abort();
8686
std::exit(code);
8787
}
@@ -98,7 +98,7 @@ static void CloseAllExternalUnits(const char *why) {
9898
}
9999
DescribeIEEESignaledExceptions();
100100
}
101-
if (get_main_thread_id() != std::this_thread::get_id())
101+
if (RTNAME(GetMainThreadId)() != std::this_thread::get_id())
102102
std::abort();
103103
if (isErrorStop) {
104104
std::exit(EXIT_FAILURE);

flang/include/flang/Runtime/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
#include "flang/Runtime/c-or-cpp.h"
1313
#include "flang/Runtime/entry-names.h"
14+
#include <thread>
1415

1516
struct EnvironmentDefaultList;
1617

1718
FORTRAN_EXTERN_C_BEGIN
19+
std::thread::id RTNAME(GetMainThreadId)();
1820
void RTNAME(ProgramStart)(
1921
int, const char *[], const char *[], const struct EnvironmentDefaultList *);
2022
void RTNAME(ByteswapOption)(void); // -byteswapio

0 commit comments

Comments
 (0)