Skip to content

Commit 3cd230e

Browse files
[libc][rpc] Fold can send/recv into buffer_unavailable
Left out of D149788 to simplify the diff Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149807
1 parent c8f81ee commit 3cd230e

File tree

1 file changed

+9
-13
lines changed
  • libc/src/__support/RPC

1 file changed

+9
-13
lines changed

libc/src/__support/RPC/rpc.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,9 @@ template <bool InvertInbox> struct Process {
101101
return InvertInbox ? !i : i;
102102
}
103103

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;
112107
}
113108
};
114109

@@ -174,7 +169,7 @@ template <bool T> template <typename F> LIBC_INLINE void Port<T>::send(F fill) {
174169
uint32_t in = process.load_inbox(index);
175170

176171
// 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)) {
178173
sleep_briefly();
179174
in = process.load_inbox(index);
180175
}
@@ -191,7 +186,7 @@ template <bool T> template <typename U> LIBC_INLINE void Port<T>::recv(U use) {
191186
uint32_t in = process.load_inbox(index);
192187

193188
// 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)) {
195190
sleep_briefly();
196191
in = process.load_inbox(index);
197192
}
@@ -274,7 +269,8 @@ LIBC_INLINE cpp::optional<Client::Port> Client::try_open(uint16_t opcode) {
274269

275270
// Once we acquire the index we need to check if we are in a valid sending
276271
// state.
277-
if (!can_send_data(in, out)) {
272+
273+
if (buffer_unavailable(in, out)) {
278274
lock[index].store(0, cpp::MemoryOrder::RELAXED);
279275
return cpp::nullopt;
280276
}
@@ -300,7 +296,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
300296

301297
// The server is passive, if there is no work pending don't bother
302298
// opening a port.
303-
if (!can_recv_data(in, out))
299+
if (buffer_unavailable(in, out))
304300
return cpp::nullopt;
305301

306302
// Attempt to acquire the lock on this index.
@@ -313,7 +309,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
313309
in = load_inbox(index);
314310
out = outbox[index].load(cpp::MemoryOrder::RELAXED);
315311

316-
if (!can_recv_data(in, out)) {
312+
if (buffer_unavailable(in, out)) {
317313
lock[index].store(0, cpp::MemoryOrder::RELAXED);
318314
return cpp::nullopt;
319315
}

0 commit comments

Comments
 (0)