From patchwork Fri May 3 23:12:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32510 Received: (qmail 129906 invoked by alias); 3 May 2019 23:12:37 -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 129806 invoked by uid 89); 3 May 2019 23:12:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.133) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:35 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 55B3A400D25E9 for ; Fri, 3 May 2019 18:12:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM2hJkVO90onMhM2hRemk; Fri, 03 May 2019 18:12:34 -0500 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=TlgJeZhJD6E6uIMVQIQRAOj+VOG2kEEdJfCXCc6c9us=; b=xIWVhnXaoa8K6s3R4882UpvTTE BaqS7H7P5NfxmUXFoV+dOsSDXhjXJOYATAo2pSVDFcuMK5+IAbwNIou51ALm111AsLAzE9SyasFHg Na01rG8kRKHzPAkV99VksPNHh; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:37502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMhM2-003AAO-5M; Fri, 03 May 2019 18:12:34 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 04/31] Convert target dcache to type-safe registry API Date: Fri, 3 May 2019 17:12:04 -0600 Message-Id: <20190503231231.8954-5-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes the target dcache to use the type-safe registry API. 2019-04-22 Tom Tromey * target-dcache.c (target_dcache_cleanup): Remove. (target_dcache_aspace_key): Change type. (target_dcache_init_p, target_dcache_invalidate) (target_dcache_get, target_dcache_get_or_init) (_initialize_target_dcache): Update. * dcache.h (struct dcache_deleter): New. --- gdb/ChangeLog | 9 +++++++++ gdb/dcache.h | 9 +++++++++ gdb/target-dcache.c | 34 +++++++--------------------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/gdb/dcache.h b/gdb/dcache.h index 9c29074c919..a58ac840d12 100644 --- a/gdb/dcache.h +++ b/gdb/dcache.h @@ -34,6 +34,15 @@ DCACHE *dcache_init (void); /* Free a DCACHE. */ void dcache_free (DCACHE *); +/* A deletion adapter that calls dcache_free. */ +struct dcache_deleter +{ + void operator() (DCACHE *d) const + { + dcache_free (d); + } +}; + enum target_xfer_status dcache_read_memory_partial (struct target_ops *ops, DCACHE *dcache, CORE_ADDR memaddr, gdb_byte *myaddr, diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c index 3fab9845bc3..98d5c1f83b6 100644 --- a/gdb/target-dcache.c +++ b/gdb/target-dcache.c @@ -23,16 +23,8 @@ /* The target dcache is kept per-address-space. This key lets us associate the cache with the address space. */ -static const struct address_space_data *target_dcache_aspace_key; - -/* Clean up dcache, represented by ARG, which is associated with - ASPACE. */ - -static void -target_dcache_cleanup (struct address_space *aspace, void *arg) -{ - dcache_free ((DCACHE *) arg); -} +static const struct address_space_key + target_dcache_aspace_key; /* Target dcache is initialized or not. */ @@ -40,8 +32,7 @@ int target_dcache_init_p (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); return (dcache != NULL); } @@ -52,8 +43,7 @@ void target_dcache_invalidate (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); if (dcache != NULL) dcache_invalidate (dcache); @@ -65,11 +55,7 @@ target_dcache_invalidate (void) DCACHE * target_dcache_get (void) { - DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); - - return dcache; + return target_dcache_aspace_key.get (current_program_space->aspace); } /* Return the target dcache. If it is not initialized yet, initialize @@ -79,14 +65,12 @@ DCACHE * target_dcache_get_or_init (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); if (dcache == NULL) { dcache = dcache_init (); - set_address_space_data (current_program_space->aspace, - target_dcache_aspace_key, dcache); + target_dcache_aspace_key.set (current_program_space->aspace, dcache); } return dcache; @@ -193,8 +177,4 @@ access is on."), set_code_cache, show_code_cache, &setlist, &showlist); - - target_dcache_aspace_key - = register_address_space_data_with_cleanup (NULL, - target_dcache_cleanup); }