diff options
author | Tom Tromey <tom@tromey.com> | 2020-12-11 09:21:53 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-12-11 09:21:55 -0700 |
commit | bfcb9db853c41ffff74c77d338b8b1378781aa0e (patch) | |
tree | 528ca883d8200bcbbac7b80e2be980679cc8f4af /gdb/thread.c | |
parent | d634cd0bcef830f2c8b9a544f1f0621fa382e2cc (diff) | |
download | gdb-bfcb9db853c41ffff74c77d338b8b1378781aa0e.zip gdb-bfcb9db853c41ffff74c77d338b8b1378781aa0e.tar.gz gdb-bfcb9db853c41ffff74c77d338b8b1378781aa0e.tar.bz2 |
Remove scoped_inc_dec_ref
We can remove scoped_inc_dec_ref by changing the sole user to instead
keep a vector of thread_info_ref objects. This removes some manual
reference counting and simplifies the code a bit.
gdb/ChangeLog
2020-12-11 Tom Tromey <tom@tromey.com>
* thread.c (class scoped_inc_dec_ref): Remove.
(tp_array_compar_ascending, tp_array_compar_descending): Change
parameter types.
(thread_apply_all_command): Use thread_info_ref.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r-- | gdb/thread.c | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/gdb/thread.c b/gdb/thread.c index 856bdee..dd88f12 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -58,29 +58,6 @@ static int highest_thread_num; /* The current/selected thread. */ static thread_info *current_thread_; -/* RAII type used to increase / decrease the refcount of each thread - in a given list of threads. */ - -class scoped_inc_dec_ref -{ -public: - explicit scoped_inc_dec_ref (const std::vector<thread_info *> &thrds) - : m_thrds (thrds) - { - for (thread_info *thr : m_thrds) - thr->incref (); - } - - ~scoped_inc_dec_ref () - { - for (thread_info *thr : m_thrds) - thr->decref (); - } - -private: - const std::vector<thread_info *> &m_thrds; -}; - /* Returns true if THR is the current thread. */ static bool @@ -1468,7 +1445,7 @@ print_thread_id (struct thread_info *thr) ascending order. */ static bool -tp_array_compar_ascending (const thread_info *a, const thread_info *b) +tp_array_compar_ascending (const thread_info_ref &a, const thread_info_ref &b) { if (a->inf->num != b->inf->num) return a->inf->num < b->inf->num; @@ -1481,7 +1458,7 @@ tp_array_compar_ascending (const thread_info *a, const thread_info *b) descending order. */ static bool -tp_array_compar_descending (const thread_info *a, const thread_info *b) +tp_array_compar_descending (const thread_info_ref &a, const thread_info_ref &b) { if (a->inf->num != b->inf->num) return a->inf->num > b->inf->num; @@ -1619,17 +1596,13 @@ thread_apply_all_command (const char *cmd, int from_tty) thread, in case the command is one that wipes threads. E.g., detach, kill, disconnect, etc., or even normally continuing over an inferior or thread exit. */ - std::vector<thread_info *> thr_list_cpy; + std::vector<thread_info_ref> thr_list_cpy; thr_list_cpy.reserve (tc); for (thread_info *tp : all_non_exited_threads ()) - thr_list_cpy.push_back (tp); + thr_list_cpy.push_back (thread_info_ref::new_reference (tp)); gdb_assert (thr_list_cpy.size () == tc); - /* Increment the refcounts, and restore them back on scope - exit. */ - scoped_inc_dec_ref inc_dec_ref (thr_list_cpy); - auto *sorter = (ascending ? tp_array_compar_ascending : tp_array_compar_descending); @@ -1637,9 +1610,9 @@ thread_apply_all_command (const char *cmd, int from_tty) scoped_restore_current_thread restore_thread; - for (thread_info *thr : thr_list_cpy) - if (switch_to_thread_if_alive (thr)) - thr_try_catch_cmd (thr, cmd, from_tty, flags); + for (thread_info_ref &thr : thr_list_cpy) + if (switch_to_thread_if_alive (thr.get ())) + thr_try_catch_cmd (thr.get (), cmd, from_tty, flags); } } |