| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include <new> |
| 10 | |
| 11 | #include "include/atomic_support.h" |
| 12 | |
| 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 |
| 26 | |
| 27 | #if defined(_LIBPCPP_DEFINE_NEW_HANDLER) |
| 28 | |
| 29 | namespace std { // purposefully not versioned |
| 30 | |
| 31 | static constinit std::new_handler __new_handler = nullptr; |
| 32 | |
| 33 | new_handler set_new_handler(new_handler handler) noexcept { return __libcpp_atomic_exchange(&__new_handler, handler); } |
| 34 | |
| 35 | new_handler get_new_handler() noexcept { return __libcpp_atomic_load(&__new_handler); } |
| 36 | |
| 37 | } // namespace std |
| 38 | |
| 39 | #endif // _LIBPCPP_DEFINE_NEW_HANDLER |
| 40 | |