From 731f534f918cfaa35c20b5eb6220a8eba4819f04 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 10 Apr 2018 14:49:30 +0100 Subject: Replace finish_thread_state_cleanup with a RAII class gdb/ChangeLog: 2018-04-10 Pedro Alves * gdbthread.h (finish_thread_state_cleanup): Delete declaration. (scoped_finish_thread_state): New class. * infcmd.c (run_command_1): Use it instead of finish_thread_state cleanup. * infrun.c (proceed, prepare_for_detach, wait_for_inferior) (fetch_inferior_event, normal_stop): Likewise. * thread.c (finish_thread_state_cleanup): Delete. --- gdb/gdbthread.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'gdb/gdbthread.h') diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 9b468db..09ea5ba 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -567,10 +567,33 @@ extern int threads_are_executing (void); Notifications are only emitted if the thread state did change. */ extern void finish_thread_state (ptid_t ptid); -/* Same as FINISH_THREAD_STATE, but with an interface suitable to be - registered as a cleanup. PTID_P points to the ptid_t that is - passed to FINISH_THREAD_STATE. */ -extern void finish_thread_state_cleanup (void *ptid_p); +/* Calls finish_thread_state on scope exit, unless release() is called + to disengage. */ +class scoped_finish_thread_state +{ +public: + explicit scoped_finish_thread_state (ptid_t ptid) + : m_ptid (ptid) + {} + + ~scoped_finish_thread_state () + { + if (!m_released) + finish_thread_state (m_ptid); + } + + /* Disengage. */ + void release () + { + m_released = true; + } + + DISABLE_COPY_AND_ASSIGN (scoped_finish_thread_state); + +private: + bool m_released = false; + ptid_t m_ptid; +}; /* Commands with a prefix of `thread'. */ extern struct cmd_list_element *thread_cmd_list; -- cgit v1.1