[v3,04/17] Use forward_scope_exit for scoped_finish_thread_state

Message ID 20190123152131.29893-5-palves@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves Jan. 23, 2019, 3:21 p.m. UTC
  This reimplements the manually-written scoped_finish_thread_state
class as a forward_scope_exit instanciation.  forward_scope_exit has
the same interface as scoped_finish_thread_state, so nothing else has
to change.

A forward_scope_exit is preferred over make_scope_exit here because
infrun.c:normal_stop needs to wrap scoped_finish_thread_state in a
gdb::optional.  Since we need the type there, might as well use it
everywhere.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
	    Andrew Burgess  <andrew.burgess@embecosm.com>

	* gdbthread.h: Include "common/forward-scope-exit.h".
	(scoped_finish_thread_state): Redefine custom class in terms of
	forward_scope_exit.
---
 gdb/gdbthread.h | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)
  

Comments

Tom Tromey Jan. 23, 2019, 5:10 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> This reimplements the manually-written scoped_finish_thread_state
Pedro> class as a forward_scope_exit instanciation.  forward_scope_exit has

Typo in the commit message, "instantiation".

Tom
  

Patch

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 95db69605e..c35a54e75d 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -32,6 +32,7 @@  struct symtab;
 #include "cli/cli-utils.h"
 #include "common/refcounted-object.h"
 #include "common-gdbthread.h"
+#include "common/forward-scope-exit.h"
 
 struct inferior;
 
@@ -612,31 +613,8 @@  extern void finish_thread_state (ptid_t ptid);
 
 /* 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;
-};
+using scoped_finish_thread_state
+  = FORWARD_SCOPE_EXIT (finish_thread_state);
 
 /* Commands with a prefix of `thread'.  */
 extern struct cmd_list_element *thread_cmd_list;