Path: blob/main/system/lib/llvm-libc/src/stdlib/atexit.cpp
6175 views
//===-- Implementation of atexit ------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/stdlib/atexit.h"9#include "hdr/types/atexithandler_t.h"10#include "src/__support/common.h"11#include "src/__support/macros/config.h"12#include "src/stdlib/exit_handler.h"1314namespace LIBC_NAMESPACE_DECL {1516constinit ExitCallbackList atexit_callbacks;17Mutex handler_list_mtx(false, false, false, false);18[[gnu::weak]] extern void teardown_main_tls();1920extern "C" {2122int __cxa_atexit(AtExitCallback *callback, void *payload, void *) {23return add_atexit_unit(atexit_callbacks, {callback, payload});24}2526void __cxa_finalize(void *dso) {27if (!dso) {28call_exit_callbacks(atexit_callbacks);29if (teardown_main_tls)30teardown_main_tls();31}32}3334} // extern "C"3536LLVM_LIBC_FUNCTION(int, atexit, (__atexithandler_t callback)) {37return add_atexit_unit(38atexit_callbacks,39{&stdc_at_exit_func, reinterpret_cast<void *>(callback)});40}4142} // namespace LIBC_NAMESPACE_DECL434445