1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 #include "include/atomic_support.h"
13 #if defined(_LIBCPP_ABI_MICROSOFT)
14 # if !defined(_LIBCPP_ABI_VCRUNTIME)
15 # define _LIBPCPP_DEFINE_NEW_HANDLER
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++
24 # define _LIBPCPP_DEFINE_NEW_HANDLER
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
); }
39 #endif // _LIBPCPP_DEFINE_NEW_HANDLER