[libc-commits] [libc] 3cd230e - [libc][rpc] Fold can send/recv into buffer_unavailable

Jon Chesterfield via libc-commits libc-commits at lists.llvm.org
Thu May 4 05:09:48 PDT 2023


Author: Jon Chesterfield
Date: 2023-05-04T13:09:35+01:00
New Revision: 3cd230e0d97db02ede994eacb9de3e8aad5609b8

URL: https://github.com/llvm/llvm-project/commit/3cd230e0d97db02ede994eacb9de3e8aad5609b8
DIFF: https://github.com/llvm/llvm-project/commit/3cd230e0d97db02ede994eacb9de3e8aad5609b8.diff

LOG: [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

Added: 
    

Modified: 
    libc/src/__support/RPC/rpc.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 18b21394d4e79..337780ee9bc5e 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -101,14 +101,9 @@ template <bool InvertInbox> struct Process {
     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 @@ template <bool T> template <typename F> LIBC_INLINE void Port<T>::send(F fill) {
   uint32_t in = process.load_inbox(index);
 
   // We need to wait until we own the buffer before sending.
-  while (!Process<T>::can_send_data(in, out)) {
+  while (Process<T>::buffer_unavailable(in, out)) {
     sleep_briefly();
     in = process.load_inbox(index);
   }
@@ -191,7 +186,7 @@ template <bool T> template <typename U> LIBC_INLINE void Port<T>::recv(U use) {
   uint32_t in = process.load_inbox(index);
 
   // We need to wait until we own the buffer before receiving.
-  while (!Process<T>::can_recv_data(in, out)) {
+  while (Process<T>::buffer_unavailable(in, out)) {
     sleep_briefly();
     in = process.load_inbox(index);
   }
@@ -274,7 +269,8 @@ LIBC_INLINE cpp::optional<Client::Port> Client::try_open(uint16_t opcode) {
 
   // 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 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
 
   // 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,7 +309,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
   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;
   }


        


More information about the libc-commits mailing list