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
15
16namespace symbian::concurrency {
17
18class TaskGroup {
19 public:
20 TaskGroup() = default;
21 TaskGroup(const TaskGroup&) = delete;
22 TaskGroup& operator=(const TaskGroup&) = delete;
23
25 if (!closed_) {
26 Cancel();
27 }
28 }
29
30 // A child is already running or registered with its OS completion owner.
31 // Add does not create a worker or transfer ownership of native buffers.
32 bool Add(Task child) {
33 if (closed_ || !child.valid()) {
34 return false;
35 }
36 children_.push_back(std::move(child));
37 return true;
38 }
39
40 void Cancel() const {
41 if (closed_) {
42 joined_.Cancel();
43 return;
44 }
45 for (const auto& child : children_) {
46 child.Cancel();
47 }
48 }
49
50 // Finish is the asynchronous join point. Every child settles before the
51 // returned Task publishes the first error or Unit success. Cancel on that
52 // Task forwards to all children, but completion remains producer-owned.
54 if (closed_) {
55 return joined_;
56 }
57 closed_ = true;
58 auto joined = JoinAll(std::move(children_));
59 joined_ =
60 Then(joined,
61 [](const absl::StatusOr<std::vector<absl::StatusOr<Unit>>>& all)
62 -> absl::StatusOr<Unit> {
63 if (!all.ok()) {
64 return all.status();
65 }
66 for (const auto& child : all.value()) {
67 if (!child.ok()) {
68 return child.status();
69 }
70 }
71 return Unit{};
72 });
73 return joined_;
74 }
75
76 private:
77 std::vector<Task> children_;
78 Task joined_;
79 bool closed_ = false;
80};
81
82} // namespace symbian::concurrency
83
84#endif // SYMBIAN_CONCURRENCY_TASK_GROUP_H_
Definition bounded_channel.h:38
bool Cancel() const
Definition future.h:146
Definition task_group.h:18
~TaskGroup()
Definition task_group.h:24
bool Add(Task child)
Definition task_group.h:32
Task Finish()
Definition task_group.h:53
void Cancel() const
Definition task_group.h:40
TaskGroup(const TaskGroup &)=delete
TaskGroup & operator=(const TaskGroup &)=delete
Definition bounded_channel.h:32
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:281
Definition future.h:33