summaryrefslogtreecommitdiff
path: root/src/experimental/memory_resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/memory_resource.cpp')
-rw-r--r--src/experimental/memory_resource.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/experimental/memory_resource.cpp b/src/experimental/memory_resource.cpp
index 7f0052f2b50a..9aa077942b0d 100644
--- a/src/experimental/memory_resource.cpp
+++ b/src/experimental/memory_resource.cpp
@@ -1,9 +1,8 @@
//===------------------------ memory_resource.cpp -------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -13,6 +12,9 @@
#include "atomic"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#include "mutex"
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
+#pragma comment(lib, "pthread")
+#endif
#endif
_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
@@ -26,19 +28,23 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
: public memory_resource
{
-public:
- ~__new_delete_memory_resource_imp() = default;
-
-protected:
- virtual void* do_allocate(size_t __size, size_t __align)
- { return _VSTD::__libcpp_allocate(__size, __align); /* FIXME */}
+ void *do_allocate(size_t size, size_t align) override {
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+ if (__is_overaligned_for_new(align))
+ __throw_bad_alloc();
+#endif
+ return _VSTD::__libcpp_allocate(size, align);
+ }
- virtual void do_deallocate(void* __p, size_t __n, size_t __align) {
- _VSTD::__libcpp_deallocate(__p, __n, __align); /* FIXME */
+ void do_deallocate(void *p, size_t n, size_t align) override {
+ _VSTD::__libcpp_deallocate(p, n, align);
}
- virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
- { return &__other == this; }
+ bool do_is_equal(memory_resource const & other) const _NOEXCEPT override
+ { return &other == this; }
+
+public:
+ ~__new_delete_memory_resource_imp() override = default;
};
// null_memory_resource()