Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
inline_pump.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// http://www.apache.org/licenses/LICENSE-2.0
4//
5// Guest no-exceptions adaptation of A11
6// cpp/a11/concurrency/inline_pump.h at
7// fcccb8cb6e1e67d7ba0822ac14cece9ee4c7091b.
8
9#ifndef SYMBIAN_CONCURRENCY_INLINE_PUMP_H_
10#define SYMBIAN_CONCURRENCY_INLINE_PUMP_H_
11
12#include <cstddef>
13#include <string_view>
14#include <utility>
15
16#include <absl/base/nullability.h>
17
18#include "thread/boost_primitives.h"
19
20namespace symbian::concurrency {
21
23 size_t depth = 0;
24 bool again = false;
25};
26
27template <typename Once>
28void DriveInline(thread::Mutex* absl_nonnull mu,
29 InlinePumpState* absl_nullable state,
30 [[maybe_unused]] std::string_view name, Once&& once,
31 size_t max_depth = 4) {
32 {
33 thread::MutexLock lock(mu);
34 if (state->depth >= max_depth) {
35 state->again = true;
36 return;
37 }
38 ++state->depth;
39 }
40 while (true) {
41 once();
42 thread::MutexLock lock(mu);
43 if (!state->again) {
44 --state->depth;
45 return;
46 }
47 state->again = false;
48 }
49}
50
51// The caller must hold the same mutex passed to DriveInline.
52inline bool PumpIsDriving(const InlinePumpState& state) {
53 return state.depth > 0;
54}
55
56} // namespace symbian::concurrency
57
58#endif // SYMBIAN_CONCURRENCY_INLINE_PUMP_H_
Definition bounded_channel.h:41
Definition boost_primitives.h:97
Definition boost_primitives.h:36
Definition bounded_channel.h:35
void DriveInline(thread::Mutex *absl_nonnull mu, InlinePumpState *absl_nullable state, std::string_view name, Once &&once, size_t max_depth=4)
Definition inline_pump.h:28
bool PumpIsDriving(const InlinePumpState &state)
Definition inline_pump.h:52
Definition inline_pump.h:22
size_t depth
Definition inline_pump.h:23
bool again
Definition inline_pump.h:24