Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
executor.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors and the Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3// Adapted from A11 cpp/thread/thread/executor.h at
4// fcccb8cb6e1e67d7ba0822ac14cece9ee4c7091b.
5
6#ifndef THREAD_EXECUTOR_H_
7#define THREAD_EXECUTOR_H_
8
9#include <cstddef>
10#include <functional>
11#include <memory>
12#include <utility>
13
14#include <absl/base/nullability.h>
15
16#include "absl/functional/any_invocable.h"
17#include "absl/status/status.h"
18#include "absl/time/clock.h"
19#include "absl/time/time.h"
20
21namespace thread {
22
23// Short nonblocking callbacks run on one shared host worker pool without
24// committing a fiber stack. A callback must not synchronously wait on work
25// that needs the same pool to make progress.
26void Post(absl::AnyInvocable<void() &&> work);
27void PostAt(absl::Time deadline, absl::AnyInvocable<void() &&> work);
28
29inline void PostAfter(absl::Duration delay,
30 absl::AnyInvocable<void() &&> work) {
31 PostAt(absl::Now() + delay, std::move(work));
32}
33
35 absl::AnyInvocable<void* absl_nonnull() const> release;
36 absl::AnyInvocable<void(void* absl_nonnull) const> acquire;
37};
38
39// Installs the host-lock release/reacquire pair used around an idle scheduler
40// park. Install before running fibers. Clearing the pair affects future parks;
41// an active park retains the old callbacks until it returns.
43
44// A policy controls ready-fiber order on one OS thread. PickNext must return
45// an index less than ready_count and must not block, throw or enter Python.
46struct SchedulerPolicy {
47 std::function<size_t(size_t ready_count)> pick_next;
48};
49
50// Installs a policy for the calling OS thread before its first SDK fiber.
51// Once Boost owns that thread's scheduler, replacing it is not supported.
52absl::Status SetCurrentSchedulerPolicy(std::shared_ptr<SchedulerPolicy> policy);
53
54namespace internal {
55void EnsureCurrentScheduler();
56}
57
58} // namespace thread
59
60#endif // THREAD_EXECUTOR_H_
Definition channel.h:29
void PostAfter(absl::Duration delay, absl::AnyInvocable< void() && > work)
Definition executor.h:29
void PostAt(absl::Time deadline, absl::AnyInvocable< void() && > work)
Definition thread_pool.cc:148
absl::Status SetCurrentSchedulerPolicy(std::shared_ptr< SchedulerPolicy > policy)
Definition executor.cc:127
void Post(absl::AnyInvocable< void() && > work)
Definition thread_pool.cc:144
void SetSchedulerParkGuard(SchedulerParkGuard guard)
Definition executor.cc:117
Definition executor.h:34
absl::AnyInvocable< void(void *absl_nonnull) const > acquire
Definition executor.h:36
absl::AnyInvocable< void *absl_nonnull() const > release
Definition executor.h:35
Definition fiber.h:39
std::function< size_t(size_t ready_count)> pick_next
Definition executor.h:47