aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2024-04-04 13:33:19 -0500
committerJoseph Huber <huberjn@outlook.com>2024-04-04 13:34:52 -0500
commit8004ce236795d48063c636d1ce4818ebcb526b21 (patch)
tree1d9ead286107493226e90e01e02479131a2c061e
parent5ae143da459a73d0f6fc796d42c3fabf3ab5f9e8 (diff)
downloadllvm-8004ce236795d48063c636d1ce4818ebcb526b21.zip
llvm-8004ce236795d48063c636d1ce4818ebcb526b21.tar.gz
llvm-8004ce236795d48063c636d1ce4818ebcb526b21.tar.bz2
[libc] Move thread sync when closing port earlier
Summary: This synchronization should be done before we handle the logic relating to closing the port. This isn't majorly important now but it would break if we ever decided to run a server on the GPU.
-rw-r--r--libc/src/__support/RPC/rpc.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 5dcae51..05506c0 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -198,12 +198,9 @@ template <bool Invert> struct Process {
/// convergent, otherwise the compiler will sink the store and deadlock.
[[clang::convergent]] LIBC_INLINE void unlock(uint64_t lane_mask,
uint32_t index) {
- // Do not move any writes past the unlock
+ // Do not move any writes past the unlock.
atomic_thread_fence(cpp::MemoryOrder::RELEASE);
- // Wait for other threads in the warp to finish using the lock
- gpu::sync_lane(lane_mask);
-
// Use exactly one thread to clear the nth bit in the lock array Must
// restrict to a single thread to avoid one thread dropping the lock, then
// an unrelated warp claiming the lock, then a second thread in this warp
@@ -331,6 +328,9 @@ public:
LIBC_INLINE uint16_t get_index() const { return index; }
LIBC_INLINE void close() {
+ // Wait for all lanes to finish using the port.
+ gpu::sync_lane(lane_mask);
+
// The server is passive, if it own the buffer when it closes we need to
// give ownership back to the client.
if (owns_buffer && T)