Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
selectables.h
Go to the documentation of this file.
1// Copyright 2026 The Action Engine Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef THREAD_FIBER_SELECTABLES_H_
16#define THREAD_FIBER_SELECTABLES_H_
17
18#include <atomic>
19
20#include <absl/base/thread_annotations.h>
21#include <absl/log/check.h>
22
23#include "thread/boost_primitives.h"
24#include "thread/cases.h"
25
26namespace thread {
27// PermanentEvent --------------- Provides a level-triggered event which may be
28// added to a Select statement.
29class PermanentEvent final : public internal::Selectable {
30 public:
31 PermanentEvent() = default;
32
33 ~PermanentEvent() override {
34 thread::MutexLock lock(&mu_);
35 DCHECK(cases_to_be_selected_ == nullptr);
36 }
37
40
41 // Signal that the event has occurred. Any Selectors on this event will be
42 // immediately notified, future Select statements against this event will be
43 // non-blocking. May only be called once.
44 void Notify();
45
46 // Returns true if Notify() has been called. False otherwise.
47 bool HasBeenNotified() const;
48
49 // May be passed to Select. Will always evaluate immediately for an event
50 // that has already been notified. Once the case has been signalled, then
51 // deleting the PermanentEvent will not interfere with the caller of Notify().
52 Case OnEvent() const {
53 Case c = {const_cast<PermanentEvent*>(this)};
54 return c;
55 }
56
57 // Implementation of Selectable interface.
58 bool Handle(internal::CaseInSelectClause* absl_nonnull case_state,
59 bool enqueue) override;
60 void Unregister(
61 internal::CaseInSelectClause* absl_nonnull case_state) override;
62
63 private:
64 friend class Fiber;
65
66 mutable thread::Mutex mu_;
67 std::atomic<bool> notified_{false};
68
69 internal::CaseInSelectClause* absl_nullable cases_to_be_selected_
70 ABSL_GUARDED_BY(mu_) = nullptr;
71};
72
73// NonSelectableCase() ------------------- Provides a 'null' case which will
74// never evaluate as ready by Select.
76
77// AlwaysSelectableCase() ---------------------- Provides case which will always
78// evaluate as ready by Select.
80} // namespace thread
81
82#endif // THREAD_FIBER_SELECTABLES_H_
Definition fiber.h:82
Definition boost_primitives.h:95
Definition boost_primitives.h:34
Definition selectables.h:15
PermanentEvent & operator=(const PermanentEvent &)=delete
bool HasBeenNotified() const
PermanentEvent(const PermanentEvent &)=delete
~PermanentEvent() override
Definition selectables.h:33
void Unregister(internal::CaseInSelectClause *case_state) override
Definition selectables.cc:34
bool Handle(internal::CaseInSelectClause *case_state, bool enqueue) override
Definition selectables.cc:21
Case OnEvent() const
Definition selectables.h:52
Definition channel.h:29
Case NonSelectableCase()
Definition selectables.cc:91
Case AlwaysSelectableCase()
Definition selectables.cc:95
A Case represents a selectable case in a Select statement.
Definition cases.h:55