The Pedigree Project 0.1
Readiness.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#ifndef PEDIGREE_KERNEL_PROCESS_READINESS_H
9#define PEDIGREE_KERNEL_PROCESS_READINESS_H
10
11#include "pedigree/kernel/compiler.h"
12#include "pedigree/kernel/processor/types.h"
13#include "pedigree/kernel/utilities/SharedPointer.h"
14
15using ReadyMask = uint32_t;
16
17enum ReadyFlag : ReadyMask {
18 ReadyNone = 0,
19 ReadyRead = 1U << 0,
20 ReadyPriority = 1U << 1,
21 ReadyWrite = 1U << 2,
22 ReadyError = 1U << 3,
23 ReadyHangup = 1U << 4,
24 ReadyReadHangup = 1U << 5,
25 ReadyInvalid = 1U << 6,
26 ReadyAll = ReadyRead | ReadyPriority | ReadyWrite | ReadyError | ReadyHangup | ReadyReadHangup |
27 ReadyInvalid,
28};
29
32 ReadinessGenerations() : read(0), priority(0), write(0), error(0), hangup(0), readHangup(0) {}
33
34 uint64_t read;
35 uint64_t priority;
36 uint64_t write;
37 uint64_t error;
38 uint64_t hangup;
39 uint64_t readHangup;
40};
41
42class ReadinessState;
43class ReadinessTarget;
44
46class EXPORTED_PUBLIC ReadinessObserver {
47 public:
48 virtual ~ReadinessObserver() = default;
49
54 virtual void readinessChanged(ReadyMask mask) = 0;
55};
56
63class EXPORTED_PUBLIC ReadinessSubscription {
64 public:
68
69 ReadinessSubscription& operator=(ReadinessSubscription&& other) noexcept;
70
71 explicit operator bool() const;
72 void reset();
73
74 private:
75 friend class ReadinessSource;
76
78 ReadinessSubscription& operator=(const ReadinessSubscription&) = delete;
79
83};
84
86class EXPORTED_PUBLIC ReadinessSource {
87 public:
89 virtual ~ReadinessSource();
90
95 MUST_USE_RESULT bool subscribeReadiness(ReadyMask interest,
97 ReadinessSubscription& subscription);
98
106 virtual ReadinessGenerations readinessGenerations();
107
108 protected:
110 void notifyReadiness(ReadyMask mask);
111
113 void closeReadiness(ReadyMask mask = ReadyInvalid | ReadyHangup);
114
115 private:
116 ReadinessSource(const ReadinessSource&) = delete;
117 ReadinessSource& operator=(const ReadinessSource&) = delete;
118
119 SharedPointer<ReadinessState> m_ReadinessState;
120};
121
122#endif
virtual void readinessChanged(ReadyMask mask)=0