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

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Nov 24 19:46:17 PST 2026


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

>From a4b85d8158733a3bf3054c17ed87ae95dfcba08e Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 24 Nov 2026 16:59:49 -0600
Subject: [PATCH 1/2] [libc] Allow RPC doorbells when compiling with MSVC

Summary:
These can be supported through the PAL abstraction under HSA.
---
 libc/shared/rpc.h                    |  8 ++++----
 libc/test/shared/shared_rpc_test.cpp | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

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));
+}

>From 1a586ff89dd7d0eea69f844bf09a647d4a5db053 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 24 Nov 2026 21:46:05 -0600
Subject: [PATCH 2/2] w32

---
 libc/shared/rpc.h                    | 4 ++++
 libc/test/shared/shared_rpc_test.cpp | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libc/shared/rpc.h b/libc/shared/rpc.h
index e9c3f7032034a0..6584dedf8b75eb 100644
--- a/libc/shared/rpc.h
+++ b/libc/shared/rpc.h
@@ -154,6 +154,7 @@ 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 _M_IX86
     if (!doorbell->value)
       return;
 
@@ -170,16 +171,19 @@ 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 _M_IX86
     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 ca412b1cbb1eb1..0e5f3513823d32 100644
--- a/libc/test/shared/shared_rpc_test.cpp
+++ b/libc/test/shared/shared_rpc_test.cpp
@@ -68,6 +68,7 @@ TEST(LlvmLibcSharedRpcTest, TestIncrement) {
   ProcB.unlock(lane_mask, index);
 }
 
+#ifndef _M_IX86
 TEST(LlvmLibcSharedRpcTest, TestDoorbell) {
   constexpr uint32_t port_count = 1;
   constexpr uint32_t lane_size = 1;
@@ -86,3 +87,4 @@ TEST(LlvmLibcSharedRpcTest, TestDoorbell) {
   server.finish(1);
   EXPECT_EQ(value, uint64_t(0));
 }
+#endif



More information about the libc-commits mailing list