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 <memory>
11#include <utility>
12
13#include "absl/functional/any_invocable.h"
14#include "absl/status/status.h"
15#include "absl/time/clock.h"
16#include "absl/time/time.h"
17
18namespace thread {
19
20// Short nonblocking callbacks run on one shared host worker pool without
21// committing a fiber stack. A callback must not synchronously wait on work
22// that needs the same pool to make progress.
23void Post(absl::AnyInvocable<void() &&> work);
24void PostAt(absl::Time deadline, absl::AnyInvocable<void() &&> work);
25
26inline void PostAfter(absl::Duration delay,
27 absl::AnyInvocable<void() &&> work) {
28 PostAt(absl::Now() + delay, std::move(work));
29}
30
32 absl::AnyInvocable<void*() const> release;
33 absl::AnyInvocable<void(void*) const> acquire;
34};
35
36// Installs the host-lock release/reacquire pair used around an idle scheduler
37// park. Install before running fibers. Clearing the pair affects future parks;
38// an active park retains the old callbacks until it returns.
40
41// A policy controls ready-fiber order on one OS thread. PickNext must return
42// an index less than ready_count and must not block or enter Python.
43class SchedulerPolicy {
44 public:
45 virtual ~SchedulerPolicy() = default;
46 virtual size_t PickNext(size_t ready_count) noexcept = 0;
47};
48
49// Installs a policy for the calling OS thread before its first SDK fiber.
50// Once Boost owns that thread's scheduler, replacing it is not supported.
51absl::Status SetCurrentSchedulerPolicy(std::shared_ptr<SchedulerPolicy> policy);
52
53namespace internal {
54void EnsureCurrentScheduler();
55}
56
57} // namespace thread
58
59#endif // THREAD_EXECUTOR_H_
Definition fiber.h:36
virtual ~SchedulerPolicy()=default
virtual size_t PickNext(size_t ready_count) noexcept=0
Definition channel.h:29
void PostAfter(absl::Duration delay, absl::AnyInvocable< void() && > work)
Definition executor.h:26
void PostAt(absl::Time deadline, absl::AnyInvocable< void() && > work)
Definition thread_pool.cc:146
absl::Status SetCurrentSchedulerPolicy(std::shared_ptr< SchedulerPolicy > policy)
Definition executor.cc:130
void Post(absl::AnyInvocable< void() && > work)
Definition thread_pool.cc:142
void SetSchedulerParkGuard(SchedulerParkGuard guard)
Definition executor.cc:120
Definition executor.h:31
absl::AnyInvocable< void(void *) const > acquire
Definition executor.h:33
absl::AnyInvocable< void *() const > release
Definition executor.h:32