Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
fiber.h
Go to the documentation of this file.
1// Copyright 2026 The Action Engine Authors and the 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// Bounded host adaptation of A11 cpp/thread/thread/fiber.h at
6// fcccb8cb6e1e67d7ba0822ac14cece9ee4c7091b. The callable runs on a
7// Boost-backed fiber pinned to its creating OS thread. This profile does not
8// implement A11 trees, Select, pool scheduling or forced-unwind cancellation.
9
10#ifndef THREAD_FIBER_H_
11#define THREAD_FIBER_H_
12
13#include <memory>
14#include <type_traits>
15#include <utility>
16
17#include "absl/functional/any_invocable.h"
18#include "absl/status/status.h"
19
20namespace thread {
21
22struct Case;
23
24class Fiber {
25 public:
26 using Work = absl::AnyInvocable<void() &&>;
27
28 explicit Fiber(Work work);
29
30 template <typename F>
31 requires(std::is_invocable_r_v<void, std::decay_t<F>> &&
32 !std::is_same_v<std::decay_t<F>, Work>) explicit Fiber(F&& work)
33 : Fiber(Work(std::forward<F>(work))) {}
34
35 Fiber(const Fiber&) = delete;
36 Fiber& operator=(const Fiber&) = delete;
37 Fiber(Fiber&&) = delete;
38 Fiber& operator=(Fiber&&) = delete;
39
40 // Join is required before destruction. No forced unwind or detach occurs.
42
43 // Cancellation is cooperative: work can inspect Current()->Cancelled().
44 void Cancel() noexcept;
45 bool Cancelled() const noexcept;
46 Case OnCancel() const;
47 bool Finished() const noexcept;
48
49 // Must be called on the creating OS thread. A wrong-thread join returns
50 // FailedPrecondition without disturbing ownership; a second join does too.
51 absl::Status Join();
52
53 // Null outside an SDK-owned fiber. This differs from A11's root placeholder.
54 static Fiber* Current() noexcept;
55
56 private:
57 struct Impl;
58 std::unique_ptr<Impl> impl_;
59};
60
61} // namespace thread
62
63namespace thread {
64bool Cancelled();
66} // namespace thread
67
68#endif // THREAD_FIBER_H_
Definition fiber.h:82
Fiber(Fiber &&)=delete
Fiber(const Fiber &)=delete
Case OnCancel() const
Definition fiber.cc:285
void Cancel() noexcept
bool Cancelled() const noexcept
Definition fiber.cc:281
bool Finished() const noexcept
Definition fiber.h:101
static Fiber * Current() noexcept
Definition fiber.cc:270
Fiber(F &&work)
Definition fiber.h:32
absl::AnyInvocable< void() && > Work
Definition fiber.h:84
absl::Status Join()
Definition fiber.cc:73
Fiber & operator=(Fiber &&)=delete
Fiber & operator=(const Fiber &)=delete
Definition exception_count.cc:8
Definition channel.h:29
A Case represents a selectable case in a Select statement.
Definition cases.h:55
Definition fiber.cc:24