@@ -101,14 +101,9 @@ template <bool InvertInbox> struct Process {
101
101
return InvertInbox ? !i : i;
102
102
}
103
103
104
- // / Determines if this process owns the buffer for a send.
105
- LIBC_INLINE static bool can_send_data (uint32_t in, uint32_t out) {
106
- return in == out;
107
- }
108
-
109
- // / Determines if this process owns the buffer for a receive.
110
- LIBC_INLINE static bool can_recv_data (uint32_t in, uint32_t out) {
111
- return in == out;
104
+ // / Determines if this process needs to wait for ownership of the buffer
105
+ LIBC_INLINE static bool buffer_unavailable (uint32_t in, uint32_t out) {
106
+ return in != out;
112
107
}
113
108
};
114
109
@@ -174,7 +169,7 @@ template <bool T> template <typename F> LIBC_INLINE void Port<T>::send(F fill) {
174
169
uint32_t in = process.load_inbox (index);
175
170
176
171
// We need to wait until we own the buffer before sending.
177
- while (! Process<T>::can_send_data (in, out)) {
172
+ while (Process<T>::buffer_unavailable (in, out)) {
178
173
sleep_briefly ();
179
174
in = process.load_inbox (index);
180
175
}
@@ -191,7 +186,7 @@ template <bool T> template <typename U> LIBC_INLINE void Port<T>::recv(U use) {
191
186
uint32_t in = process.load_inbox (index);
192
187
193
188
// We need to wait until we own the buffer before receiving.
194
- while (! Process<T>::can_recv_data (in, out)) {
189
+ while (Process<T>::buffer_unavailable (in, out)) {
195
190
sleep_briefly ();
196
191
in = process.load_inbox (index);
197
192
}
@@ -274,7 +269,8 @@ LIBC_INLINE cpp::optional<Client::Port> Client::try_open(uint16_t opcode) {
274
269
275
270
// Once we acquire the index we need to check if we are in a valid sending
276
271
// state.
277
- if (!can_send_data (in, out)) {
272
+
273
+ if (buffer_unavailable (in, out)) {
278
274
lock[index].store (0 , cpp::MemoryOrder::RELAXED);
279
275
return cpp::nullopt;
280
276
}
@@ -300,7 +296,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
300
296
301
297
// The server is passive, if there is no work pending don't bother
302
298
// opening a port.
303
- if (! can_recv_data (in, out))
299
+ if (buffer_unavailable (in, out))
304
300
return cpp::nullopt;
305
301
306
302
// Attempt to acquire the lock on this index.
@@ -313,7 +309,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
313
309
in = load_inbox (index);
314
310
out = outbox[index].load (cpp::MemoryOrder::RELAXED);
315
311
316
- if (! can_recv_data (in, out)) {
312
+ if (buffer_unavailable (in, out)) {
317
313
lock[index].store (0 , cpp::MemoryOrder::RELAXED);
318
314
return cpp::nullopt;
319
315
}
0 commit comments