|
9 | 9 | #include "async_simple/uthread/Uthread.h" |
10 | 10 |
|
11 | 11 | using namespace std; |
| 12 | +using namespace async_simple::uthread::internal; |
12 | 13 |
|
13 | 14 | static std::atomic<unsigned> get_stack_holder_count = 0; |
14 | 15 | static std::atomic<unsigned> delete_stack_holder_count = 0; |
15 | 16 |
|
16 | | -namespace async_simple { |
17 | | -namespace uthread { |
18 | | -namespace internal { |
19 | | - |
20 | | -stack_holder get_stack_holder(unsigned stack_size) { |
21 | | - get_stack_holder_count++; |
22 | | - return stack_holder(new char[stack_size]); |
23 | | -} |
24 | | - |
25 | | -void stack_deleter::operator()(char* ptr) const noexcept { |
26 | | - delete_stack_holder_count++; |
27 | | - delete[] ptr; |
28 | | -} |
29 | | -} |
30 | | -} |
31 | | -} |
32 | | - |
33 | 17 | namespace async_simple { |
34 | 18 | namespace uthread { |
35 | 19 | class UthreadAllocSwapTest : public FUTURE_TESTBASE { |
36 | 20 | public: |
37 | 21 | UthreadAllocSwapTest() : _executor(4) {} |
38 | | - void caseSetUp() override {} |
39 | | - void caseTearDown() override {} |
| 22 | + |
| 23 | + void caseSetUp() override { |
| 24 | + get_stack_holder_count = 0; |
| 25 | + delete_stack_holder_count = 0; |
| 26 | + |
| 27 | + set_stack_allocator([](unsigned stack_size) -> stack_holder { |
| 28 | + get_stack_holder_count++; |
| 29 | + return stack_holder(new char[stack_size]); |
| 30 | + }); |
| 31 | + set_stack_deleter([](char* ptr) noexcept { |
| 32 | + delete_stack_holder_count++; |
| 33 | + delete[] ptr; |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + void caseTearDown() override { |
| 38 | + set_stack_allocator(nullptr); |
| 39 | + set_stack_deleter(nullptr); |
| 40 | + } |
40 | 41 |
|
41 | 42 | template <class Func> |
42 | 43 | void delayedTask(Func&& func, std::size_t ms) { |
|
0 commit comments