[libc-commits] [PATCH] D158365: [libc] Remove 'try_open' from the client interface

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Aug 21 04:43:56 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6970920ca6ab: [libc] Remove 'try_open' from the client interface (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158365

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
@@ -348,7 +348,6 @@
   LIBC_INLINE ~Client() = default;
 
   using Port = rpc::Port<false, Packet<gpu::LANE_SIZE>>;
-  template <uint16_t opcode> LIBC_INLINE cpp::optional<Port> try_open();
   template <uint16_t opcode> LIBC_INLINE Port open();
 
   LIBC_INLINE void reset(uint32_t port_count, void *buffer) {
@@ -517,15 +516,19 @@
   }
 }
 
-/// Attempts to open a port to use as the client. The client can only open a
-/// port if we find an index that is in a valid sending state. That is, there
-/// are send operations pending that haven't been serviced on this port. Each
-/// port instance uses an associated \p opcode to tell the server what to do.
-template <uint16_t opcode>
-[[clang::convergent]] LIBC_INLINE cpp::optional<Client::Port>
-Client::try_open() {
-  // Perform a naive linear scan for a port that can be opened to send data.
-  for (uint32_t index = 0; index < process.port_count; ++index) {
+/// Continually attempts to open a port to use as the client. The client can
+/// only open a port if we find an index that is in a valid sending state. That
+/// is, there are send operations pending that haven't been serviced on this
+/// port. Each port instance uses an associated \p opcode to tell the server
+/// what to do.
+template <uint16_t opcode> LIBC_INLINE Client::Port Client::open() {
+  // Repeatedly perform a naive linear scan for a port that can be opened to
+  // send data.
+  for (uint32_t index = 0;; ++index) {
+    // Start from the beginning if we run out of ports to check.
+    if (index >= process.port_count)
+      index = 0;
+
     // Attempt to acquire the lock on this index.
     uint64_t lane_mask = gpu::get_lane_mask();
     if (!process.try_lock(lane_mask, index))
@@ -548,15 +551,6 @@
     gpu::sync_lane(lane_mask);
     return Port(process, lane_mask, index, out);
   }
-  return cpp::nullopt;
-}
-
-template <uint16_t opcode> LIBC_INLINE Client::Port Client::open() {
-  for (;;) {
-    if (cpp::optional<Client::Port> p = try_open<opcode>())
-      return cpp::move(p.value());
-    sleep_briefly();
-  }
 }
 
 /// Attempts to open a port to use as the server. The server can only open a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158365.551983.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230821/c8db3140/attachment-0001.bin>


More information about the libc-commits mailing list