[libc-commits] [libc] [libc] Allow RPC doorbells when compiling with MSVC (PR #245843)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 24 17:55:41 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
These can be supported through the PAL abstraction under HSA.


---
Full diff: https://github.com/llvm/llvm-project/pull/245843.diff


2 Files Affected:

- (modified) libc/shared/rpc.h (+4-4) 
- (modified) libc/test/shared/shared_rpc_test.cpp (+19) 


``````````diff
diff --git a/libc/shared/rpc.h b/libc/shared/rpc.h
index c4a96bf33891cd..e9c3f7032034a0 100644
--- a/libc/shared/rpc.h
+++ b/libc/shared/rpc.h
@@ -34,6 +34,10 @@
   _InterlockedOr((volatile long *)(src), (long)(val))
 #define __scoped_atomic_fetch_and(src, val, ord, scp)                          \
   _InterlockedAnd((volatile long *)(src), (long)(val))
+#define __scoped_atomic_fetch_add(src, val, ord, scp)                          \
+  _InterlockedExchangeAdd64((volatile __int64 *)(src), (__int64)(val))
+#define __scoped_atomic_fetch_sub(src, val, ord, scp)                          \
+  _InterlockedExchangeAdd64((volatile __int64 *)(src), -(__int64)(val))
 #else // GNU atomic support.
 #define __scoped_atomic_load_n(src, ord, scp) __atomic_load_n(src, ord)
 #define __scoped_atomic_store_n(dst, src, ord, scp)                            \
@@ -150,7 +154,6 @@ template <bool Invert> struct Process {
 
   /// Ring the doorbell if the protocol was configured with one.
   RPC_ATTRS void notify(uint64_t lane_mask) const {
-#ifndef _MSC_VER
     if (!doorbell->value)
       return;
 
@@ -167,19 +170,16 @@ template <bool Invert> struct Process {
         signal_interrupt(event_id);
       }
     }
-#endif
   }
 
   /// Decrement the doorbell signal if the protocol is using one.
   RPC_ATTRS void finish(uint64_t lane_mask) const {
-#ifndef _MSC_VER
     if (!doorbell->value)
       return;
 
     if (rpc::is_first_lane(lane_mask))
       __scoped_atomic_fetch_sub(doorbell->value, 1UL, __ATOMIC_RELAXED,
                                 __MEMORY_SCOPE_SYSTEM);
-#endif
   }
 
   /// Retrieve the inbox state from memory shared between processes.
diff --git a/libc/test/shared/shared_rpc_test.cpp b/libc/test/shared/shared_rpc_test.cpp
index 69861dd1026033..ca412b1cbb1eb1 100644
--- a/libc/test/shared/shared_rpc_test.cpp
+++ b/libc/test/shared/shared_rpc_test.cpp
@@ -67,3 +67,22 @@ TEST(LlvmLibcSharedRpcTest, TestIncrement) {
   ProcA.unlock(lane_mask, index);
   ProcB.unlock(lane_mask, index);
 }
+
+TEST(LlvmLibcSharedRpcTest, TestDoorbell) {
+  constexpr uint32_t port_count = 1;
+  constexpr uint32_t lane_size = 1;
+  alignas(64)
+      uint8_t buffer[::rpc::Server::allocation_size(lane_size, port_count)] = {
+          0};
+  alignas(8) uint64_t value = 0;
+
+  auto *doorbell = reinterpret_cast<::rpc::Doorbell *>(buffer);
+  doorbell->value = &value;
+
+  ::rpc::Process<false> client(port_count, buffer);
+  ::rpc::Process<true> server(port_count, buffer);
+  client.notify(1);
+  EXPECT_EQ(value, uint64_t(1));
+  server.finish(1);
+  EXPECT_EQ(value, uint64_t(0));
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/245843


More information about the libc-commits mailing list