diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h --- a/libc/src/__support/RPC/rpc.h +++ b/libc/src/__support/RPC/rpc.h @@ -101,14 +101,9 @@ return InvertInbox ? !i : i; } - /// Determines if this process owns the buffer for a send. - LIBC_INLINE static bool can_send_data(uint32_t in, uint32_t out) { - return in == out; - } - - /// Determines if this process owns the buffer for a receive. - LIBC_INLINE static bool can_recv_data(uint32_t in, uint32_t out) { - return in == out; + /// Determines if this process needs to wait for ownership of the buffer + LIBC_INLINE static bool buffer_unavailable(uint32_t in, uint32_t out) { + return in != out; } }; @@ -174,7 +169,7 @@ uint32_t in = process.load_inbox(index); // We need to wait until we own the buffer before sending. - while (!Process::can_send_data(in, out)) { + while (Process::buffer_unavailable(in, out)) { sleep_briefly(); in = process.load_inbox(index); } @@ -191,7 +186,7 @@ uint32_t in = process.load_inbox(index); // We need to wait until we own the buffer before receiving. - while (!Process::can_recv_data(in, out)) { + while (Process::buffer_unavailable(in, out)) { sleep_briefly(); in = process.load_inbox(index); } @@ -274,7 +269,8 @@ // Once we acquire the index we need to check if we are in a valid sending // state. - if (!can_send_data(in, out)) { + + if (buffer_unavailable(in, out)) { lock[index].store(0, cpp::MemoryOrder::RELAXED); return cpp::nullopt; } @@ -300,7 +296,7 @@ // The server is passive, if there is no work pending don't bother // opening a port. - if (!can_recv_data(in, out)) + if (buffer_unavailable(in, out)) return cpp::nullopt; // Attempt to acquire the lock on this index. @@ -313,8 +309,9 @@ in = load_inbox(index); out = outbox[index].load(cpp::MemoryOrder::RELAXED); - if (!can_recv_data(in, out)) { + if (buffer_unavailable(in, out)) { lock[index].store(0, cpp::MemoryOrder::RELAXED); + return cpp::nullopt; }