async: scope: allow blocks before started
In some cases it may be helpful to be able to block on a scope
before work has begun on that scope. Add state tracking to know
when the scope has first started.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I9ee48aa19344b80124aa9409a4a7e368eb025882
diff --git a/src/async/scope.cpp b/src/async/scope.cpp
index 353c52b..a990e41 100644
--- a/src/async/scope.cpp
+++ b/src/async/scope.cpp
@@ -16,6 +16,7 @@
void scope::started_task() noexcept
{
std::lock_guard l{lock};
+ started = true;
++pending_count;
}
@@ -74,7 +75,11 @@
{
std::lock_guard l{s.lock};
- if (s.pending_count == 0)
+ if (!s.started)
+ {
+ done = false;
+ }
+ else if (s.pending_count == 0)
{
done = true;
}