To allow for sharing of AddressSpaces between multiple masters. Signed-off-by: Peter Crosthwaite <peter.crosthwa...@xilinx.com> ---
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