[libc-commits] [libc] 71d2b65 - [libc] Make the RPC interfaces move only

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri May 5 11:45:32 PDT 2023


Author: Joseph Huber
Date: 2023-05-05T13:45:23-05:00
New Revision: 71d2b65e3659a75ea3e3aa376f4f46d187126885

URL: https://github.com/llvm/llvm-project/commit/71d2b65e3659a75ea3e3aa376f4f46d187126885
DIFF: https://github.com/llvm/llvm-project/commit/71d2b65e3659a75ea3e3aa376f4f46d187126885.diff

LOG: [libc] Make the RPC interfaces move only

This patch uses the changed interface in D149972 to make these classes
move-only. The `Port` class could be further refined to be
construct-only in a future patch, but for now this makes it more
difficult to misuse the interface.

Depends on D149972

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D149974

Added: 
    

Modified: 
    libc/src/__support/RPC/rpc.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 5395c4e57332..19be921047b2 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -98,8 +98,10 @@ constexpr uint64_t default_port_count = 64;
 ///
 template <bool InvertInbox> struct Process {
   LIBC_INLINE Process() = default;
-  LIBC_INLINE Process(const Process &) = default;
-  LIBC_INLINE Process &operator=(const Process &) = default;
+  LIBC_INLINE Process(const Process &) = delete;
+  LIBC_INLINE Process &operator=(const Process &) = delete;
+  LIBC_INLINE Process(Process &&) = default;
+  LIBC_INLINE Process &operator=(Process &&) = default;
   LIBC_INLINE ~Process() = default;
 
   uint64_t port_count;
@@ -236,8 +238,10 @@ template <bool T> struct Port {
   LIBC_INLINE Port(Process<T> &process, uint64_t lane_mask, uint64_t index,
                    uint32_t out)
       : process(process), lane_mask(lane_mask), index(index), out(out) {}
-  LIBC_INLINE Port(const Port &) = default;
+  LIBC_INLINE Port(const Port &) = delete;
   LIBC_INLINE Port &operator=(const Port &) = delete;
+  LIBC_INLINE Port(Port &&) = default;
+  LIBC_INLINE Port &operator=(Port &&) = default;
   LIBC_INLINE ~Port() = default;
 
   template <typename U> LIBC_INLINE void recv(U use);
@@ -264,8 +268,8 @@ template <bool T> struct Port {
 /// The RPC client used to make requests to the server.
 struct Client : public Process<false> {
   LIBC_INLINE Client() = default;
-  LIBC_INLINE Client(const Client &) = default;
-  LIBC_INLINE Client &operator=(const Client &) = default;
+  LIBC_INLINE Client(const Client &) = delete;
+  LIBC_INLINE Client &operator=(const Client &) = delete;
   LIBC_INLINE ~Client() = default;
 
   using Port = rpc::Port<false>;
@@ -276,8 +280,8 @@ struct Client : public Process<false> {
 /// The RPC server used to respond to the client.
 struct Server : public Process<true> {
   LIBC_INLINE Server() = default;
-  LIBC_INLINE Server(const Server &) = default;
-  LIBC_INLINE Server &operator=(const Server &) = default;
+  LIBC_INLINE Server(const Server &) = delete;
+  LIBC_INLINE Server &operator=(const Server &) = delete;
   LIBC_INLINE ~Server() = default;
 
   using Port = rpc::Port<true>;
@@ -444,7 +448,7 @@ Client::try_open(uint16_t opcode) {
 LIBC_INLINE Client::Port Client::open(uint16_t opcode) {
   for (;;) {
     if (cpp::optional<Client::Port> p = try_open(opcode))
-      return p.value();
+      return cpp::move(p.value());
     sleep_briefly();
   }
 }
@@ -488,7 +492,7 @@ Server::try_open() {
 LIBC_INLINE Server::Port Server::open() {
   for (;;) {
     if (cpp::optional<Server::Port> p = try_open())
-      return p.value();
+      return cpp::move(p.value());
     sleep_briefly();
   }
 }


        


More information about the libc-commits mailing list