diff --git a/libc/src/__support/OSUtil/gpu/io.cpp b/libc/src/__support/OSUtil/gpu/io.cpp --- a/libc/src/__support/OSUtil/gpu/io.cpp +++ b/libc/src/__support/OSUtil/gpu/io.cpp @@ -15,7 +15,7 @@ namespace __llvm_libc { void write_to_stderr(cpp::string_view msg) { - rpc::Client::Port port = rpc::client.open(rpc::PRINT_TO_STDERR); + rpc::Client::Port port = rpc::client.open(); port.send_n(msg.data(), msg.size()); port.close(); } diff --git a/libc/src/__support/OSUtil/gpu/quick_exit.cpp b/libc/src/__support/OSUtil/gpu/quick_exit.cpp --- a/libc/src/__support/OSUtil/gpu/quick_exit.cpp +++ b/libc/src/__support/OSUtil/gpu/quick_exit.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { void quick_exit(int status) { - rpc::Client::Port port = rpc::client.open(rpc::EXIT); + rpc::Client::Port port = rpc::client.open(); port.send([&](rpc::Buffer *buffer) { reinterpret_cast(buffer->data)[0] = status; }); diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h --- a/libc/src/__support/RPC/rpc.h +++ b/libc/src/__support/RPC/rpc.h @@ -273,8 +273,8 @@ LIBC_INLINE ~Client() = default; using Port = rpc::Port; - LIBC_INLINE cpp::optional try_open(uint16_t opcode); - LIBC_INLINE Port open(uint16_t opcode); + template LIBC_INLINE cpp::optional try_open(); + template LIBC_INLINE Port open(); }; /// The RPC server used to respond to the client. @@ -411,10 +411,9 @@ /// 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. -/// Opening a port is only valid if the `opcode` is the sam accross every -/// participating thread. +template [[clang::convergent]] LIBC_INLINE cpp::optional -Client::try_open(uint16_t opcode) { +Client::try_open() { // Perform a naive linear scan for a port that can be opened to send data. for (uint64_t index = 0; index < port_count; ++index) { // Attempt to acquire the lock on this index. @@ -445,9 +444,9 @@ return cpp::nullopt; } -LIBC_INLINE Client::Port Client::open(uint16_t opcode) { +template LIBC_INLINE Client::Port Client::open() { for (;;) { - if (cpp::optional p = try_open(opcode)) + if (cpp::optional p = try_open()) return cpp::move(p.value()); sleep_briefly(); } diff --git a/libc/test/integration/startup/gpu/rpc_test.cpp b/libc/test/integration/startup/gpu/rpc_test.cpp --- a/libc/test/integration/startup/gpu/rpc_test.cpp +++ b/libc/test/integration/startup/gpu/rpc_test.cpp @@ -17,7 +17,7 @@ 10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id(); uint64_t cnt = 0; for (uint32_t i = 0; i < num_additions; ++i) { - rpc::Client::Port port = rpc::client.open(rpc::TEST_INCREMENT); + rpc::Client::Port port = rpc::client.open(); port.send_and_recv( [=](rpc::Buffer *buffer) { reinterpret_cast(buffer->data)[0] = cnt; @@ -32,7 +32,7 @@ // Test to ensure that the RPC mechanism doesn't hang on divergence. static void test_noop(uint8_t data) { - rpc::Client::Port port = rpc::client.open(rpc::NOOP); + rpc::Client::Port port = rpc::client.open(); port.send([=](rpc::Buffer *buffer) { buffer->data[0] = data; }); port.close(); }