Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / src / new_handler.cpp
blob49c21d85f59084d53f60f828e652e23c9942ae0a
1 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include <new>
11 #include "include/atomic_support.h"
13 #if defined(_LIBCPP_ABI_MICROSOFT)
14 # if !defined(_LIBCPP_ABI_VCRUNTIME)
15 # define _LIBPCPP_DEFINE_NEW_HANDLER
16 # endif
17 #elif defined(LIBCXX_BUILDING_LIBCXXABI)
18 // nothing to do, we use the one from libc++abi
19 #elif defined(LIBCXXRT)
20 # define _LIBPCPP_DEFINE_NEW_HANDLER
21 #elif defined(__GLIBCXX__)
22 // nothing to do, we use the one from libstdc++/libsupc++
23 #else
24 # define _LIBPCPP_DEFINE_NEW_HANDLER
25 #endif
27 #if defined(_LIBPCPP_DEFINE_NEW_HANDLER)
29 namespace std { // purposefully not versioned
31 static constinit std::new_handler __new_handler = nullptr;
33 new_handler set_new_handler(new_handler handler) noexcept { return __libcpp_atomic_exchange(&__new_handler, handler); }
35 new_handler get_new_handler() noexcept { return __libcpp_atomic_load(&__new_handler); }
37 } // namespace std
39 #endif // _LIBPCPP_DEFINE_NEW_HANDLER