8#include "pedigree/kernel/LockGuard.h"
9#include "pedigree/kernel/Log.h"
10#include "pedigree/kernel/process/Mutex.h"
11#include "pedigree/kernel/process/OperationBarrier.h"
12#include "pedigree/kernel/process/Readiness.h"
13#include "pedigree/kernel/utilities/List.h"
14#include "pedigree/kernel/utilities/Vector.h"
15#include "pedigree/kernel/utilities/utility.h"
18constexpr ReadyMask AlwaysReported = ReadyError | ReadyHangup | ReadyInvalid;
24 : m_Interest(interest), m_pObserver(observer), m_Notifications() {}
27 if (!m_Notifications.isClosedAndDrained()) {
32 bool interestedIn(ReadyMask mask)
const {
33 return (mask & (m_Interest | AlwaysReported)) != 0;
36 void notify(ReadyMask mask) {
38 if (!m_Notifications.
tryAcquire(notification)) {
61 if (m_Targets.
count()) {
62 FATAL(
"ReadinessState destroyed with live subscriptions.");
80 it != m_Targets.
end(); ++it) {
91 void notify(ReadyMask mask) {
95 for (
const auto& target : m_Targets) {
96 if (target->interestedIn(mask)) {
102 for (
auto& target : targets) {
103 target->notify(mask);
107 void close(ReadyMask mask) {
116 for (
const auto& target : m_Targets) {
117 if (target->interestedIn(mask)) {
123 for (
auto& target : targets) {
124 target->notify(mask);
134ReadinessSubscription::ReadinessSubscription() : m_State(), m_Target(), m_Observer() {}
137 : m_State(pedigree_std::move(other.m_State)),
138 m_Target(pedigree_std::move(other.m_Target)),
139 m_Observer(pedigree_std::move(other.m_Observer)) {}
141ReadinessSubscription::~ReadinessSubscription() {
146 if (
this != &other) {
148 m_State = pedigree_std::move(other.m_State);
149 m_Target = pedigree_std::move(other.m_Target);
150 m_Observer = pedigree_std::move(other.m_Observer);
155ReadinessSubscription::operator bool()
const {
156 return static_cast<bool>(m_State) &&
static_cast<bool>(m_Target);
159void ReadinessSubscription::reset() {
162 if (state && target) {
163 state->remove(target);
171ReadinessSource::ReadinessSource() : m_ReadinessState(new
ReadinessState) {}
173ReadinessSource::~ReadinessSource() {
184 subscription.reset();
185 if (!observer || !interest) {
190 subscription.m_State = m_ReadinessState;
191 subscription.m_Target = target;
192 subscription.m_Observer = observer;
193 if (!m_ReadinessState->add(target)) {
194 subscription.reset();
An iterator applicable for many data structures.
MUST_USE_RESULT bool tryAcquire(Lease &lease)
virtual void readinessChanged(ReadyMask mask)=0
void notifyReadiness(ReadyMask mask)
void closeReadiness(ReadyMask mask=ReadyInvalid|ReadyHangup)
MUST_USE_RESULT bool subscribeReadiness(ReadyMask interest, const SharedPointer< ReadinessObserver > &observer, ReadinessSubscription &subscription)
virtual ReadinessGenerations readinessGenerations()
A vector / dynamic array.
Iterator erase(Iterator &Iter)
void pushBack(const T &value)
void pushBack(const T &value)