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/base/nullability.h>
18
19#include "absl/functional/any_invocable.h"
20#include "absl/status/status.h"
21
22namespace thread {
23
24struct Case;
25
26class Fiber {
27 public:
28 using Work = absl::AnyInvocable<void() &&>;
29
30 explicit Fiber(Work work);
31
32 template <typename F>
33 requires(std::is_invocable_r_v<void, std::decay_t<F>> &&
34 !std::is_same_v<std::decay_t<F>, Work>) explicit Fiber(F&& work)
35 : Fiber(Work(std::forward<F>(work))) {}
36
37 Fiber(const Fiber&) = delete;
38 Fiber& operator=(const Fiber&) = delete;
39 Fiber(Fiber&&) = delete;
40 Fiber& operator=(Fiber&&) = delete;
41
42 // Join is required before destruction. No forced unwind or detach occurs.
44
45 // Cancellation is cooperative: work can inspect Current()->Cancelled().
46 void Cancel() noexcept;
47 bool Cancelled() const noexcept;
48 Case OnCancel() const;
49 bool Finished() const noexcept;
50
51 // Must be called on the creating OS thread. A wrong-thread join returns
52 // FailedPrecondition without disturbing ownership; a second join does too.
53 absl::Status Join();
54
55 // Null outside an SDK-owned fiber. This differs from A11's root placeholder.
56 static Fiber* absl_nullable Current() noexcept;
57
58 private:
59 struct Impl;
60 std::unique_ptr<Impl> impl_;
61};
62
63} // namespace thread
64
65namespace thread {
66bool Cancelled();
68} // namespace thread
69
70#endif // THREAD_FIBER_H_
Definition fiber.h:89
Fiber(Fiber &&)=delete
Fiber(const Fiber &)=delete
Case OnCancel() const
Definition fiber.cc:287
void Cancel() noexcept
bool Cancelled() const noexcept
Definition fiber.cc:283
bool Finished() const noexcept
Definition fiber.h:108
static Fiber *absl_nullable Current() noexcept
Definition fiber.cc:272
Fiber(F &&work)
Definition fiber.h:34
absl::AnyInvocable< void() && > Work
Definition fiber.h:91
absl::Status Join()
Definition fiber.cc:74
Fiber & operator=(Fiber &&)=delete
Fiber & operator=(const Fiber &)=delete
Definition native_camera_stream.cc:19
Definition channel.h:29
A Case represents a selectable case in a Select statement.
Definition cases.h:57
Definition fiber.cc:25