From patchwork Wed Jan 23 15:21:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31193 Received: (qmail 67067 invoked by alias); 23 Jan 2019 15:21:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 66751 invoked by uid 89); 23 Jan 2019 15:21:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1640 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Jan 2019 15:21:54 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2D3489ACD; Wed, 23 Jan 2019 15:21:52 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1563A67147; Wed, 23 Jan 2019 15:21:51 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey , Andrew Burgess Subject: [PATCH v3 17/17] Use scope_exit in regcache.c Date: Wed, 23 Jan 2019 15:21:31 +0000 Message-Id: <20190123152131.29893-18-palves@redhat.com> In-Reply-To: <20190123152131.29893-1-palves@redhat.com> References: <20190123152131.29893-1-palves@redhat.com> From: Tom Tromey This removes the regcache_invalidator class in favor of a scope_exit. This seems like an improvement (albeit a minor one) because regcache_invalidator is only used in a single spot. gdb/ChangeLog 2019-01-22 Tom Tromey Pedro Alves * regcache.c (class regcache_invalidator): Remove. (regcache::raw_write): Use make_scope_exit. --- gdb/regcache.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 4a68390c5f..a354e15d2d 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -219,37 +219,6 @@ reg_buffer::arch () const return m_descr->gdbarch; } -/* Cleanup class for invalidating a register. */ - -class regcache_invalidator -{ -public: - - regcache_invalidator (struct regcache *regcache, int regnum) - : m_regcache (regcache), - m_regnum (regnum) - { - } - - ~regcache_invalidator () - { - if (m_regcache != nullptr) - m_regcache->invalidate (m_regnum); - } - - DISABLE_COPY_AND_ASSIGN (regcache_invalidator); - - void release () - { - m_regcache = nullptr; - } - -private: - - struct regcache *m_regcache; - int m_regnum; -}; - /* Return a pointer to register REGNUM's buffer cache. */ gdb_byte * @@ -769,7 +738,8 @@ regcache::raw_write (int regnum, const gdb_byte *buf) /* Invalidate the register after it is written, in case of a failure. */ - regcache_invalidator invalidator (this, regnum); + auto invalidator + = make_scope_exit ([&] { this->invalidate (regnum); }); target_store_registers (this, regnum);