Pass unique_ptr to add_thread_with_info
authorTom Tromey <tom@tromey.com>
Thu, 10 Mar 2022 23:56:57 +0000 (16:56 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 10 Aug 2023 16:50:37 +0000 (10:50 -0600)
This changes add_thread_with_info to accept a unique_ptr, making it
clear that it takes ownership of the passed-in pointer.

I can't test the AIX or Darwin changes, but I think they are
relatively obvious.

gdb/aix-thread.c
gdb/darwin-nat.c
gdb/gdbthread.h
gdb/linux-thread-db.c
gdb/thread.c

index 74cc67c942b3197a342d677aff2fc6508f5e5969..8c45116f355d6d426eab9532d09a1c7a2dc6d640 100644 (file)
@@ -899,7 +899,7 @@ sync_threadlists (pid_t pid)
 
          thread = add_thread_with_info (proc_target,
                                         ptid_t (pid, 0, pbuf[pi].pthid),
-                                        priv);
+                                        private_thread_info_up (priv));
 
          pi++;
        }
index 4cf2d9f387a18914a320be292250d332b84f065c..588e9e2a34578d35741a928491d14aab17322bb7 100644 (file)
@@ -351,7 +351,8 @@ darwin_nat_target::check_new_threads (inferior *inf)
          pti->msg_state = DARWIN_RUNNING;
 
          /* Add the new thread.  */
-         add_thread_with_info (this, ptid_t (inf->pid, 0, new_id), pti);
+         add_thread_with_info (this, ptid_t (inf->pid, 0, new_id),
+                               private_thread_info_up (pti));
          new_thread_vec.push_back (pti);
          new_ix++;
          continue;
index d294be6762b6d7b8762a06e52a44a50913a0fc8d..baff68aee925af8c81edcdadcf96d3a60b5358c7 100644 (file)
@@ -222,6 +222,9 @@ struct private_thread_info
   virtual ~private_thread_info () = 0;
 };
 
+/* Unique pointer wrapper for private_thread_info.  */
+using private_thread_info_up = std::unique_ptr<private_thread_info>;
+
 /* Threads are intrusively refcounted objects.  Being the
    user-selected thread is normally considered an implicit strong
    reference and is thus not accounted in the refcount, unlike
@@ -522,7 +525,7 @@ public:
   struct frame_id initiating_frame = null_frame_id;
 
   /* Private data used by the target vector implementation.  */
-  std::unique_ptr<private_thread_info> priv;
+  private_thread_info_up priv;
 
   /* Branch trace information for this thread.  */
   struct btrace_thread_info btrace {};
@@ -616,7 +619,7 @@ extern struct thread_info *add_thread_silent (process_stratum_target *targ,
 /* Same as add_thread, and sets the private info.  */
 extern struct thread_info *add_thread_with_info (process_stratum_target *targ,
                                                 ptid_t ptid,
-                                                private_thread_info *);
+                                                private_thread_info_up);
 
 /* Delete thread THREAD and notify of thread exit.  If the thread is
    currently not deletable, don't actually delete it but still tag it
index 71a81aa0cb915fc1e506735f5cd90a8e6c5472c8..7d9fd57da0c2e7e985eaaaaa9897a0387607129a 100644 (file)
@@ -1366,7 +1366,8 @@ record_thread (struct thread_db_info *info,
      thread with this PTID, but it's marked exited, then the kernel
      reused the tid of an old thread.  */
   if (tp == NULL || tp->state == THREAD_EXITED)
-    tp = add_thread_with_info (info->process_target, ptid, priv);
+    tp = add_thread_with_info (info->process_target, ptid,
+                              private_thread_info_up (priv));
   else
     tp->priv.reset (priv);
 
index 7f7f035b5ab3d1b4a8060e85ec427dba43d2c016..63ed87e9aa6d8832c35ba35198515aab8091ee2d 100644 (file)
@@ -306,11 +306,11 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid)
 
 struct thread_info *
 add_thread_with_info (process_stratum_target *targ, ptid_t ptid,
-                     private_thread_info *priv)
+                     private_thread_info_up priv)
 {
   thread_info *result = add_thread_silent (targ, ptid);
 
-  result->priv.reset (priv);
+  result->priv = std::move (priv);
 
   if (print_thread_events)
     gdb_printf (_("[New %s]\n"), target_pid_to_str (ptid).c_str ());