From patchwork Wed Jan 9 03:34:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31009 Received: (qmail 37152 invoked by alias); 9 Jan 2019 03:34:38 -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 36937 invoked by uid 89); 9 Jan 2019 03:34:36 -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, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.160.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Jan 2019 03:34:33 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 856A910296 for ; Tue, 8 Jan 2019 21:34:32 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id h4dUgZ2jLYTGMh4dUgKPCm; Tue, 08 Jan 2019 21:34:32 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mWj0smMsySAO0o3hrZTrHDlr8MVpbiyqiJwB0zHfSk8=; b=k4m9irGHmjYZ8P1ZHNCzO8wpif JpAx8EzozROAJW6RY247CghKSpc62x7aVtisDycx0HvEQF4ERLvYeni+488TV7VqpSZ2MDjvtl9P9 LwQsJ70VA2OE/xpWkDa0bA+pk; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:47026 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gh4dU-000HG2-As; Tue, 08 Jan 2019 21:34:32 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/12] Use cleanup_function in regcache.c Date: Tue, 8 Jan 2019 20:34:26 -0700 Message-Id: <20190109033426.16062-13-tom@tromey.com> In-Reply-To: <20190109033426.16062-1-tom@tromey.com> References: <20190109033426.16062-1-tom@tromey.com> This removes the regcache_invalidator class in favor of a cleanup_function. This seems like an improvement (albeit a minor one) because regcache_invalidator is only used in a single spot. gdb/ChangeLog 2019-01-08 Tom Tromey * regcache.c (class regcache_invalidator): Remove. (regcache::raw_write): Use cleanup_function. --- gdb/ChangeLog | 5 +++++ gdb/regcache.c | 41 ++++++++--------------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index c51ef771be..47339a0bce 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -28,6 +28,7 @@ #include "reggroups.h" #include "observable.h" #include "regset.h" +#include "common/cleanup-function.h" #include /* @@ -219,37 +220,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,13 +739,18 @@ 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 do_invalidate + = [=] () + { + this->invalidate (regnum); + }; + cleanup_function invalidator (do_invalidate); target_store_registers (this, regnum); /* The target did not throw an error so we can discard invalidating the register. */ - invalidator.release (); + invalidator.cancel (); } void