Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
task_group.h
Go to the documentation of this file.
1// Copyright 2026 Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// http://www.apache.org/licenses/LICENSE-2.0
4//
5// Guest stackless task group built on the pinned A11 Promise/Future and
6// all-result fan-in adaptation. It owns no scheduler or native request queue.
7
8#ifndef SYMBIAN_CONCURRENCY_TASK_GROUP_H_
9#define SYMBIAN_CONCURRENCY_TASK_GROUP_H_
10
11#include <utility>
12#include <vector>
13
14#include <absl/status/status_macros.h>
15
17
18namespace symbian::concurrency {
19
20class TaskGroup {
21 public:
22 TaskGroup() = default;
23 TaskGroup(const TaskGroup&) = delete;
24 TaskGroup& operator=(const TaskGroup&) = delete;
25
27 if (!closed_) {
28 Cancel();
29 }
30 }
31
32 // A child is already running or registered with its OS completion owner.
33 // Add does not create a worker or transfer ownership of native buffers.
34 bool Add(Task child) {
35 if (closed_ || !child.valid()) {
36 return false;
37 }
38 children_.push_back(std::move(child));
39 return true;
40 }
41
42 void Cancel() const {
43 if (closed_) {
44 joined_.Cancel();
45 return;
46 }
47 for (const auto& child : children_) {
48 child.Cancel();
49 }
50 }
51
52 // Finish is the asynchronous join point. Every child settles before the
53 // returned Task publishes the first error or Unit success. Cancel on that
54 // Task forwards to all children, but completion remains producer-owned.
56 if (closed_) {
57 return joined_;
58 }
59 closed_ = true;
60 auto joined = JoinAll(std::move(children_));
61 joined_ =
62 Then(joined,
63 [](const absl::StatusOr<std::vector<absl::StatusOr<Unit>>>& all)
64 -> absl::StatusOr<Unit> {
65 ABSL_ASSIGN_OR_RETURN(const auto& results, all);
66 for (const auto& child : results) {
68 }
69 return Unit{};
70 });
71 return joined_;
72 }
73
74 private:
75 std::vector<Task> children_;
76 Task joined_;
77 bool closed_ = false;
78};
79
80} // namespace symbian::concurrency
81
82#endif // SYMBIAN_CONCURRENCY_TASK_GROUP_H_
Definition bounded_channel.h:41
bool Cancel() const
Definition future.h:148
Definition task_group.h:20
~TaskGroup()
Definition task_group.h:26
bool Add(Task child)
Definition task_group.h:34
Task Finish()
Definition task_group.h:55
void Cancel() const
Definition task_group.h:42
TaskGroup(const TaskGroup &)=delete
TaskGroup & operator=(const TaskGroup &)=delete
Definition bounded_channel.h:35
Future< std::vector< absl::StatusOr< T > > > JoinAll(std::vector< Future< T > > inputs)
Definition parallel.h:24
auto Then(const Future< T > &future, Fn transform) -> Future< typename std::invoke_result_t< Fn, const absl::StatusOr< T > & >::value_type >
Definition future.h:284
Definition future.h:35