Debian Codegraph @

libcxx/test/std/utilities/utility/mem.res/mem.res.pool/mem.res.pool.mem/sync_allocate.pass.cpp

raw
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 // UNSUPPORTED: c++03, c++11, c++14
10 // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11 // UNSUPPORTED: availability-pmr-missing
12
13 // <memory_resource>
14
15 // class synchronized_pool_resource
16
17 #include <memory_resource>
18 #include <cassert>
19
20 #include "count_new.h"
21 #include "test_macros.h"
22
23 int main(int, char**) {
24 globalMemCounter.reset();
25 {
26 auto sync1 = std::pmr::synchronized_pool_resource(std::pmr::new_delete_resource());
27 std::pmr::memory_resource& r1 = sync1;
28
29 void* ret = r1.allocate(50);
30 assert(ret);
31 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));
32 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(0));
33
34 r1.deallocate(ret, 50);
35 sync1.release();
36 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledGreaterThan(0));
37 assert(globalMemCounter.checkOutstandingNewEq(0));
38
39 globalMemCounter.reset();
40
41 ret = r1.allocate(500);
42 assert(ret);
43 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));
44 assert(globalMemCounter.checkDeleteCalledEq(0));
45
46 // Check that the destructor calls release()
47 }
48 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledGreaterThan(0));
49 assert(globalMemCounter.checkOutstandingNewEq(0));
50
51 return 0;
52 }