pool: add 'full' query
This commit is contained in:
parent
d73332034f
commit
41c9b504dc
1
pool.hpp
1
pool.hpp
@ -144,6 +144,7 @@ namespace cruft {
|
||||
auto capacity (void) const { return m_capacity; }
|
||||
auto size (void) const { return m_size.load (); }
|
||||
bool empty (void) const { return size () == 0; }
|
||||
bool full (void) const { return size () == capacity (); }
|
||||
|
||||
|
||||
// Indexing
|
||||
|
@ -28,7 +28,7 @@ check_unique_ptr (cruft::TAP::logger &tap)
|
||||
std::set<uint64_t *> uintset;
|
||||
|
||||
// Take all pointers out, checking they are unique, then replace for destruction.
|
||||
while (!uintpool.empty ())
|
||||
while (!uintpool.full ())
|
||||
uintset.insert (uintpool.allocate ());
|
||||
|
||||
tap.expect_eq (uintset.size (), uintpool.capacity (), "extracted maximum elements");
|
||||
@ -40,7 +40,7 @@ check_unique_ptr (cruft::TAP::logger &tap)
|
||||
uintset.clear ();
|
||||
|
||||
// Do the above one more time to ensure that releasing works right
|
||||
while (!uintpool.empty ())
|
||||
while (!uintpool.full ())
|
||||
uintset.insert (uintpool.allocate ());
|
||||
tap.expect_eq (uintset.size (), uintpool.capacity (), "re-extracted maximum elements");
|
||||
}
|
||||
@ -120,6 +120,24 @@ done:
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
check_size_queries (cruft::TAP::logger &tap)
|
||||
{
|
||||
cruft::pool<int> data (8);
|
||||
|
||||
tap.expect_eq (data.size (), 0u, "initial size is zero");
|
||||
tap.expect (data.empty (), "initial object is empty");
|
||||
|
||||
auto first = data.allocate ();
|
||||
tap.expect_eq (data.size (), 1u, "1 allocation has size of 1");
|
||||
tap.expect (!data.empty (), "1 allocation is not empty");
|
||||
|
||||
data.deallocate (first);
|
||||
tap.expect (data.empty (), "full deallocation is empty");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main (int, char **)
|
||||
@ -129,5 +147,6 @@ main (int, char **)
|
||||
check_unique_ptr (tap);
|
||||
check_keep_value (tap);
|
||||
check_keep_variadic_value (tap);
|
||||
check_size_queries (tap);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user