Skip to content

Commit

Permalink
Wrapping more wait calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-parent committed Jan 25, 2025
1 parent 4b13f82 commit d59c4c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
5 changes: 3 additions & 2 deletions include/stlab/test/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <iostream>
#include <mutex>

#include <stlab/concurrency/await.hpp>

/**************************************************************************************************/

namespace stlab {
Expand All @@ -42,8 +44,7 @@ struct annotate_counters {

void wait(std::size_t count) {
std::unique_lock<std::mutex> lock(_mutex);
while (count != remaining())
_condition.wait(lock);
stlab::invoke_waiting([&] { _condition.wait(lock, [&] { return count == remaining(); }); });
}

friend inline auto operator<<(std::ostream& out, const annotate_counters& x) -> std::ostream& {
Expand Down
14 changes: 5 additions & 9 deletions test/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
/**************************************************************************************************/

#include <stlab/concurrency/await.hpp>
#include <stlab/concurrency/default_executor.hpp>
#include <stlab/concurrency/serial_queue.hpp>

Expand Down Expand Up @@ -106,7 +107,7 @@ BOOST_AUTO_TEST_CASE(all_high_prio_tasks_get_executed) {
BOOST_AUTO_TEST_CASE(task_system_restarts_after_it_went_pending) {
BOOST_TEST_MESSAGE("The task system restarts after it went to pending");

atomic_bool done{false};
bool done{false};
mutex m;
condition_variable cv;

Expand All @@ -121,9 +122,7 @@ BOOST_AUTO_TEST_CASE(task_system_restarts_after_it_went_pending) {

{
unique_lock<mutex> block{m};
while (!done) {
cv.wait(block);
}
invoke_waiting([&] { cv.wait(block, [&] { return done; }); });
}

default_executor([&]() noexcept {
Expand All @@ -137,9 +136,7 @@ BOOST_AUTO_TEST_CASE(task_system_restarts_after_it_went_pending) {

{
unique_lock<mutex> block{m};
while (done) {
cv.wait(block);
}
invoke_waiting([&] { cv.wait(block, [&] { return !done; }); });
}

BOOST_REQUIRE(!done);
Expand Down Expand Up @@ -287,8 +284,7 @@ BOOST_AUTO_TEST_CASE(MeasureTiming) {
});

unique_lock<mutex> lock{block};
while (!done)
ready.wait(lock);
invoke_waiting([&]{ ready.wait(lock, [&]{ return done; }); });

while (counter < 3 * iterations) {
rest();
Expand Down

0 comments on commit d59c4c1

Please sign in to comment.