| 33 | int CtorDtorCounter::dtor_count = -1; |
| 34 | |
| 35 | void WithBoundSchedulerBase::TestUnboundedPool() |
| 36 | { |
| 37 | SUBCASE("UnboundedPool_ConstructDestruct") { |
| 38 | marl::UnboundedPool<int> pool; |
| 39 | } |
| 40 | |
| 41 | SUBCASE("BoundedPool_ConstructDestruct") { |
| 42 | marl::BoundedPool<int, 10> pool; |
| 43 | } |
| 44 | |
| 45 | SUBCASE("UnboundedPoolLoan_GetNull") { |
| 46 | marl::UnboundedPool<int>::Loan loan; |
| 47 | ASSERT_EQ(loan.get(), nullptr); |
| 48 | } |
| 49 | |
| 50 | SUBCASE("BoundedPoolLoan_GetNull") { |
| 51 | marl::BoundedPool<int, 10>::Loan loan; |
| 52 | ASSERT_EQ(loan.get(), nullptr); |
| 53 | } |
| 54 | |
| 55 | SUBCASE("UnboundedPool_Borrow") { |
| 56 | marl::UnboundedPool<int> pool; |
| 57 | for (int i = 0; i < 100; i++) { |
| 58 | pool.borrow(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | SUBCASE("UnboundedPool_ConcurrentBorrow") { |
| 63 | marl::UnboundedPool<int> pool; |
| 64 | constexpr int iterations = 10000; |
| 65 | marl::WaitGroup wg(iterations); |
| 66 | for (int i = 0; i < iterations; i++) { |
| 67 | marl::schedule([=] { |
| 68 | pool.borrow(); |
| 69 | wg.done(); |
| 70 | }); |
| 71 | } |
| 72 | wg.wait(); |
| 73 | } |
| 74 | |
| 75 | SUBCASE("BoundedPool_Borrow") { |
| 76 | marl::BoundedPool<int, 100> pool; |
| 77 | for (int i = 0; i < 100; i++) { |
| 78 | pool.borrow(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | SUBCASE("BoundedPool_ConcurrentBorrow") { |
| 83 | marl::BoundedPool<int, 10> pool; |
| 84 | constexpr int iterations = 10000; |
| 85 | marl::WaitGroup wg(iterations); |
| 86 | for (int i = 0; i < iterations; i++) { |
| 87 | marl::schedule([=] { |
| 88 | pool.borrow(); |
| 89 | wg.done(); |
| 90 | }); |
| 91 | } |
| 92 | wg.wait(); |