summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorJon Chesterfield <jonathanchesterfield@gmail.com>2023-05-04 13:09:34 +0100
committerJon Chesterfield <jonathanchesterfield@gmail.com>2023-05-04 13:09:35 +0100
commit3cd230e0d97db02ede994eacb9de3e8aad5609b8 (patch)
treebfb6f74a5e42d24c3cabcc6b9d0dfba5ea501fe9 /libc
parentc8f81ee1da325760a4bbd83c8c54ecc9645f8e20 (diff)
downloadllvm-3cd230e0d97db02ede994eacb9de3e8aad5609b8.tar.gz
[libc][rpc] Fold can send/recv into buffer_unavailable
Left out of D149788 to simplify the diff Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149807
Diffstat (limited to 'libc')
-rw-r--r--libc/src/__support/RPC/rpc.h22
1 files changed, 9 insertions, 13 deletions
diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 18b21394d4e7..337780ee9bc5 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -101,14 +101,9 @@ template <bool InvertInbox> struct Process {
return InvertInbox ? !i : i;
}
- /// Determines if this process owns the buffer for a send.
- LIBC_INLINE static bool can_send_data(uint32_t in, uint32_t out) {
- return in == out;
- }
-
- /// Determines if this process owns the buffer for a receive.
- LIBC_INLINE static bool can_recv_data(uint32_t in, uint32_t out) {
- return in == out;
+ /// Determines if this process needs to wait for ownership of the buffer
+ LIBC_INLINE static bool buffer_unavailable(uint32_t in, uint32_t out) {
+ return in != out;
}
};
@@ -174,7 +169,7 @@ template <bool T> template <typename F> LIBC_INLINE void Port<T>::send(F fill) {
uint32_t in = process.load_inbox(index);
// We need to wait until we own the buffer before sending.
- while (!Process<T>::can_send_data(in, out)) {
+ while (Process<T>::buffer_unavailable(in, out)) {
sleep_briefly();
in = process.load_inbox(index);
}
@@ -191,7 +186,7 @@ template <bool T> template <typename U> LIBC_INLINE void Port<T>::recv(U use) {
uint32_t in = process.load_inbox(index);
// We need to wait until we own the buffer before receiving.
- while (!Process<T>::can_recv_data(in, out)) {
+ while (Process<T>::buffer_unavailable(in, out)) {
sleep_briefly();
in = process.load_inbox(index);
}
@@ -274,7 +269,8 @@ LIBC_INLINE cpp::optional<Client::Port> Client::try_open(uint16_t opcode) {
// Once we acquire the index we need to check if we are in a valid sending
// state.
- if (!can_send_data(in, out)) {
+
+ if (buffer_unavailable(in, out)) {
lock[index].store(0, cpp::MemoryOrder::RELAXED);
return cpp::nullopt;
}
@@ -300,7 +296,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
// The server is passive, if there is no work pending don't bother
// opening a port.
- if (!can_recv_data(in, out))
+ if (buffer_unavailable(in, out))
return cpp::nullopt;
// Attempt to acquire the lock on this index.
@@ -313,7 +309,7 @@ LIBC_INLINE cpp::optional<Server::Port> Server::try_open() {
in = load_inbox(index);
out = outbox[index].load(cpp::MemoryOrder::RELAXED);
- if (!can_recv_data(in, out)) {
+ if (buffer_unavailable(in, out)) {
lock[index].store(0, cpp::MemoryOrder::RELAXED);
return cpp::nullopt;
}