Skip to content

Commit a3bd867

Browse files
remove extra check
1 parent 0836f08 commit a3bd867

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

libc/src/__support/threads/thread.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ ThreadAtExitCallbackMgr *get_thread_atexit_callback_mgr() {
154154
}
155155

156156
void call_atexit_callbacks(ThreadAttributes *attrib) {
157-
if (attrib->dtors_called)
158-
return;
159-
attrib->dtors_called = true;
160157
attrib->atexit_callback_mgr->call();
161158
for (size_t i = 0; i < TSS_KEY_COUNT; ++i) {
162159
TSSValueUnit &unit = tss_values[i];

libc/src/__support/threads/thread.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ struct alignas(STACK_ALIGNMENT) ThreadAttributes {
109109
ThreadReturnValue retval;
110110
ThreadAtExitCallbackMgr *atexit_callback_mgr;
111111
void *platform_data;
112-
bool dtors_called;
113112

114113
LIBC_INLINE constexpr ThreadAttributes()
115114
: detach_state(uint32_t(DetachState::DETACHED)), stack(nullptr),
116115
stacksize(0), guardsize(0), tls(0), tls_size(0), owned_stack(false),
117116
tid(-1), style(ThreadStyle::POSIX), retval(),
118-
atexit_callback_mgr(nullptr), platform_data(nullptr),
119-
dtors_called(false) {}
117+
atexit_callback_mgr(nullptr), platform_data(nullptr) {}
120118
};
121119

122120
using TSSDtor = void(void *);

libc/test/integration/src/__support/threads/double_exit_test.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ void *__dso_handle = nullptr;
1616
int __cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso);
1717
}
1818

19+
int call_num = 0;
20+
21+
[[gnu::destructor]]
22+
void check() {
23+
// This destructor should be called only once.
24+
if (call_num != 1)
25+
__builtin_trap();
26+
}
27+
1928
TEST_MAIN() {
2029
__cxa_thread_atexit_impl([](void *) { LIBC_NAMESPACE::exit(0); }, nullptr,
2130
__dso_handle);
22-
return 0;
31+
__cxa_thread_atexit_impl([](void *) { ++call_num; }, nullptr, __dso_handle);
32+
LIBC_NAMESPACE::exit(1);
2333
}

0 commit comments

Comments
 (0)