[libc-commits] [PATCH] D149807: [libc][rpc] Fold can send/recv into buffer_unavailable

Jon Chesterfield via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu May 4 03:29:16 PDT 2023


JonChesterfield updated this revision to Diff 519422.
JonChesterfield added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149807/new/

https://reviews.llvm.org/D149807

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


Index: libc/src/__support/RPC/rpc.h
===================================================================
--- libc/src/__support/RPC/rpc.h
+++ 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<T>::can_send_data(in, out)) {
+  while (Process<T>::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<T>::can_recv_data(in, out)) {
+  while (Process<T>::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,7 +309,7 @@
   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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149807.519422.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230504/9903ba5a/attachment.bin>


More information about the libc-commits mailing list