[libc-commits] [PATCH] D149807: [libc][rpc] Simplify can send/recv

Jon Chesterfield via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed May 3 18:34:51 PDT 2023


JonChesterfield created this revision.
JonChesterfield added a reviewer: jhuber6.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
JonChesterfield requested review of this revision.

Left out of D149788 <https://reviews.llvm.org/D149788> to simplify the diff


Repository:
  rG LLVM Github Monorepo

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
@@ -100,16 +100,6 @@
     uint32_t i = inbox[index].load(cpp::MemoryOrder::RELAXED);
     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;
-  }
 };
 
 /// The port provides the interface to communicate between the multiple
@@ -174,7 +164,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 (in != out) {
     sleep_briefly();
     in = process.load_inbox(index);
   }
@@ -191,7 +181,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 (in != out) {
     sleep_briefly();
     in = process.load_inbox(index);
   }
@@ -274,7 +264,7 @@
 
   // Once we acquire the index we need to check if we are in a valid sending
   // state.
-  if (!can_send_data(in, out)) {
+  if (in != out) {
     lock->store(0, cpp::MemoryOrder::RELAXED);
     return cpp::nullopt;
   }
@@ -300,7 +290,7 @@
 
   // The server is passive, if there is no work pending don't bother
   // opening a port.
-  if (!can_recv_data(in, out))
+  if (in != out)
     return cpp::nullopt;
 
   // Attempt to acquire the lock on this index.
@@ -313,7 +303,7 @@
   in = load_inbox(index);
   out = outbox->load(cpp::MemoryOrder::RELAXED);
 
-  if (!can_recv_data(in, out)) {
+  if (in != out) {
     lock->store(0, cpp::MemoryOrder::RELAXED);
     return cpp::nullopt;
   }


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


More information about the libc-commits mailing list