提交 946996e9 编写于 作者: A Avi Kivity

memory: add shorthand for invoking a callback on all listeners

Signed-off-by: NAvi Kivity <avi@redhat.com>
Reviewed-by: NRichard Henderson <rth@twiddle.net>
上级 2b50aa1f
...@@ -678,31 +678,23 @@ static void address_space_update_ioeventfds(AddressSpace *as) ...@@ -678,31 +678,23 @@ static void address_space_update_ioeventfds(AddressSpace *as)
as->ioeventfd_nb = ioeventfd_nb; as->ioeventfd_nb = ioeventfd_nb;
} }
typedef void ListenerCallback(MemoryListener *listener, #define MEMORY_LISTENER_CALL(_callback, _args...) \
MemoryRegionSection *mrs); do { \
MemoryListener *_listener; \
/* Want "void (&MemoryListener::*callback)(const MemoryRegionSection& s)" */ \
static void memory_listener_update_region(FlatRange *fr, AddressSpace *as, QLIST_FOREACH(_listener, &memory_listeners, link) { \
size_t callback_offset) _listener->_callback(_listener, ##_args); \
{ } \
MemoryRegionSection section = { } while (0)
.mr = fr->mr,
.address_space = as->root, #define MEMORY_LISTENER_UPDATE_REGION(fr, as, callback) \
.offset_within_region = fr->offset_in_region, MEMORY_LISTENER_CALL(callback, &(MemoryRegionSection) { \
.size = int128_get64(fr->addr.size), .mr = (fr)->mr, \
.offset_within_address_space = int128_get64(fr->addr.start), .address_space = (as)->root, \
}; .offset_within_region = (fr)->offset_in_region, \
MemoryListener *listener; .size = int128_get64((fr)->addr.size), \
.offset_within_address_space = int128_get64((fr)->addr.start), \
QLIST_FOREACH(listener, &memory_listeners, link) { })
ListenerCallback *callback
= *(ListenerCallback **)((void *)listener + callback_offset);
callback(listener, &section);
}
}
#define MEMORY_LISTENER_UPDATE_REGION(fr, as, callback) \
memory_listener_update_region(fr, as, offsetof(MemoryListener, callback))
static void address_space_update_topology_pass(AddressSpace *as, static void address_space_update_topology_pass(AddressSpace *as,
FlatView old_view, FlatView old_view,
...@@ -1483,23 +1475,15 @@ void memory_global_sync_dirty_bitmap(MemoryRegion *address_space) ...@@ -1483,23 +1475,15 @@ void memory_global_sync_dirty_bitmap(MemoryRegion *address_space)
void memory_global_dirty_log_start(void) void memory_global_dirty_log_start(void)
{ {
MemoryListener *listener;
cpu_physical_memory_set_dirty_tracking(1); cpu_physical_memory_set_dirty_tracking(1);
global_dirty_log = true; global_dirty_log = true;
QLIST_FOREACH(listener, &memory_listeners, link) { MEMORY_LISTENER_CALL(log_global_start);
listener->log_global_start(listener);
}
} }
void memory_global_dirty_log_stop(void) void memory_global_dirty_log_stop(void)
{ {
MemoryListener *listener;
global_dirty_log = false; global_dirty_log = false;
QLIST_FOREACH(listener, &memory_listeners, link) { MEMORY_LISTENER_CALL(log_global_stop);
listener->log_global_stop(listener);
}
cpu_physical_memory_set_dirty_tracking(0); cpu_physical_memory_set_dirty_tracking(0);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册