public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert target dcache to type-safe registry API
@ 2019-05-08 22:07 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-05-08 22:07 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=35632941c90f406f69512c9559ae7ba561f7eee8

commit 35632941c90f406f69512c9559ae7ba561f7eee8
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Apr 21 09:12:47 2019 -0600

    Convert target dcache to type-safe registry API
    
    This changes the target dcache to use the type-safe registry API.
    
    gdb/ChangeLog
    2019-05-08  Tom Tromey  <tom@tromey.com>
    
    	* 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.

Diff:
---
 gdb/ChangeLog       |  9 +++++++++
 gdb/dcache.h        |  9 +++++++++
 gdb/target-dcache.c | 34 +++++++---------------------------
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c12fdd5..5c8680b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
 2019-05-08  Tom Tromey  <tom@tromey.com>
 
+	* 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.
+
+2019-05-08  Tom Tromey  <tom@tromey.com>
+
 	* symtab.c (struct symbol_cache): Add destructor and
 	initializers.
 	(symbol_cache_key): Move.  Change type.
diff --git a/gdb/dcache.h b/gdb/dcache.h
index 9c29074..a58ac84 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 3fab984..98d5c1f 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<DCACHE, dcache_deleter>
+  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);
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-08 22:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 22:07 [binutils-gdb] Convert target dcache to type-safe registry API Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).