adt unit test - fix memory pool test

master
Francisco 4 years ago committed by Francisco Paisana
parent ec3cd9ffea
commit 9bec13731a

@ -251,22 +251,29 @@ public:
base_blocking_queue(PushingFunc push_func_, PoppingFunc pop_func_, Args&&... args) : base_blocking_queue(PushingFunc push_func_, PoppingFunc pop_func_, Args&&... args) :
circ_buffer(std::forward<Args>(args)...), push_func(push_func_), pop_func(pop_func_) circ_buffer(std::forward<Args>(args)...), push_func(push_func_), pop_func(pop_func_)
{} {}
base_blocking_queue(const base_blocking_queue&) = delete;
base_blocking_queue(base_blocking_queue&&) = delete;
base_blocking_queue& operator=(const base_blocking_queue&) = delete;
base_blocking_queue& operator=(base_blocking_queue&&) = delete;
void stop() void stop()
{ {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock<std::mutex> lock(mutex);
if (active) { if (active) {
active = false; active = false;
if (nof_waiting == 0) { if (nof_waiting > 0) {
return; // Stop pending pushing/popping threads
do {
lock.unlock();
cvar_empty.notify_all();
cvar_full.notify_all();
std::this_thread::yield();
lock.lock();
} while (nof_waiting > 0);
} }
do {
lock.unlock(); // Empty queue
cvar_empty.notify_all(); circ_buffer.clear();
cvar_full.notify_all();
std::this_thread::yield();
lock.lock();
} while (nof_waiting > 0);
} }
} }
@ -284,8 +291,7 @@ public:
bool pop_wait_until(T& obj, const std::chrono::system_clock::time_point& until) { return pop_(obj, true, &until); } bool pop_wait_until(T& obj, const std::chrono::system_clock::time_point& until) { return pop_(obj, true, &until); }
void clear() void clear()
{ {
std::lock_guard<std::mutex> lock(mutex); T obj;
T obj;
while (pop_(obj, false)) { while (pop_(obj, false)) {
} }
} }

@ -115,6 +115,7 @@ void test_fixedsize_pool()
fixed_pool->print_all_buffers(); fixed_pool->print_all_buffers();
} }
fixed_pool->print_all_buffers(); fixed_pool->print_all_buffers();
TESTASSERT(C::default_ctor_counter == C::dtor_counter);
// TEST: one thread allocates, and the other deallocates // TEST: one thread allocates, and the other deallocates
{ {

Loading…
Cancel
Save