• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Implementation header for exit_handler ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC_STDLIB_EXIT_HANDLER_H
10 #define LLVM_LIBC_SRC_STDLIB_EXIT_HANDLER_H
11 
12 #include "src/__support/CPP/mutex.h" // lock_guard
13 #include "src/__support/blockstore.h"
14 #include "src/__support/common.h"
15 #include "src/__support/fixedvector.h"
16 #include "src/__support/threads/mutex.h"
17 
18 namespace LIBC_NAMESPACE {
19 
20 using AtExitCallback = void(void *);
21 using StdCAtExitCallback = void(void);
22 constexpr size_t CALLBACK_LIST_SIZE_FOR_TESTS = 1024;
23 
24 struct AtExitUnit {
25   AtExitCallback *callback = nullptr;
26   void *payload = nullptr;
27   LIBC_INLINE constexpr AtExitUnit() = default;
AtExitUnitAtExitUnit28   LIBC_INLINE constexpr AtExitUnit(AtExitCallback *c, void *p)
29       : callback(c), payload(p) {}
30 };
31 
32 #if defined(LIBC_TARGET_ARCH_IS_GPU)
33 using ExitCallbackList = FixedVector<AtExitUnit, 64>;
34 #elif defined(LIBC_COPT_PUBLIC_PACKAGING)
35 using ExitCallbackList = ReverseOrderBlockStore<AtExitUnit, 32>;
36 #else
37 using ExitCallbackList = FixedVector<AtExitUnit, CALLBACK_LIST_SIZE_FOR_TESTS>;
38 #endif
39 
40 extern ExitCallbackList atexit_callbacks;
41 extern ExitCallbackList at_quick_exit_callbacks;
42 
43 extern Mutex handler_list_mtx;
44 
45 void stdc_at_exit_func(void *payload);
46 
47 void call_exit_callbacks(ExitCallbackList &callbacks);
48 
49 int add_atexit_unit(ExitCallbackList &callbacks, const AtExitUnit &unit);
50 
51 } // namespace LIBC_NAMESPACE
52 
53 #endif // LLVM_LIBC_SRC_STDLIB_EXIT_HANDLER_H
54