qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v1 2/6] memory: AddressSpace: Implement ref counting


From: Peter Crosthwaite
Subject: [Qemu-devel] [PATCH v1 2/6] memory: AddressSpace: Implement ref counting
Date: Mon, 25 Aug 2014 17:57:32 -0700

To allow for sharing of AddressSpaces between multiple masters.

Signed-off-by: Peter Crosthwaite <address@hidden>
---

 include/exec/memory.h | 1 +
 memory.c              | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index d165b27..18cb6b2 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -207,6 +207,7 @@ struct AddressSpace {
     /* All fields are private. */
     char *name;
     MemoryRegion *root;
+    int ref_count;
     struct FlatView *current_map;
     int ioeventfd_nb;
     struct MemoryRegionIoeventfd *ioeventfds;
diff --git a/memory.c b/memory.c
index e6014d9..27beef1 100644
--- a/memory.c
+++ b/memory.c
@@ -1930,6 +1930,7 @@ void address_space_init(AddressSpace *as, MemoryRegion 
*root, const char *name)
     }
 
     memory_region_transaction_begin();
+    as->ref_count = 1;
     as->root = root;
     as->current_map = g_new(FlatView, 1);
     flatview_init(as->current_map);
@@ -1946,6 +1947,10 @@ void address_space_destroy(AddressSpace *as)
 {
     MemoryListener *listener;
 
+    as->ref_count--;
+    if (as->ref_count) {
+        return;
+    }
     /* Flush out anything from MemoryListeners listening in on this */
     memory_region_transaction_begin();
     as->root = NULL;
-- 
2.1.0.1.g27b9230




reply via email to

[Prev in Thread] Current Thread [Next in Thread]