14 static constexpr size_t Capacity = 4096;
15 using ChangeCallback = void (*)(
void*);
16 enum class Status { Ready, Eof, WouldBlock, Interrupted, Closed, Invalid };
29 void copyTo(uint8_t* destination,
size_t count)
const;
30 void consume(
size_t accepted);
47 Result commit(
const uint8_t* source,
size_t accepted);
57 explicit PipeBuffer(ChangeCallback changed =
nullptr,
void* context =
nullptr);
62 size_t read(uint8_t* destination,
size_t count,
bool block =
true);
63 size_t write(
const uint8_t* source,
size_t count,
bool block =
true);
64 size_t writeAtomic(
const uint8_t* source,
size_t count,
bool block =
true);
65 bool canRead(
bool block);
66 bool canWrite(
bool block);
67 uint64_t readableGeneration()
const;
68 uint64_t writableGeneration()
const;
75 bool enableWrites(
bool resetIfPreviouslyDisabled =
false);
81 Result waitTransfer(
bool writing,
bool block);
82 Result transferTo(
PipeBuffer& output,
size_t maximum,
bool consume,
bool block);
85 friend class PipeBufferTestPeer;
92 explicit operator bool()
const;
102 static void lock(
Mutex& mutex);
104 static bool interrupted();
105 bool beginOperation();
107 bool readableLocked()
const;
108 bool writableLocked()
const;
109 Result readyLocked(
bool writing,
size_t minimum = 1)
const;
110 Result waitLocked(
bool writing,
size_t minimum,
bool block);
111 void changedLocked();
113 void finishResetLocked();
114 void copyOutLocked(uint8_t* destination,
size_t count)
const;
115 void appendLocked(
const uint8_t* source,
size_t count);
116 void consumeLocked(
size_t count);
118 void wakePairsLocked();
119 void linkPairLocked(
PairLink& link);
120 void unlinkPairLocked(
PairLink& link);
122 uint8_t m_Data[Capacity];
125 bool m_ReadEnabled =
true;
126 bool m_WriteEnabled =
true;
127 bool m_Closing =
false;
128 bool m_ResetPending =
false;
129 bool m_ReadReserved =
false;
130 bool m_WriteReserved =
false;
131 bool m_WasReadable =
false;
132 bool m_WasWritable =
true;
133 size_t m_ActiveOperations = 0;
141 const ChangeCallback m_Changed;
142 void*
const m_Context;