summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-02-11 15:00:12 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2015-02-16 17:30:19 +0100
commit439c5e02d59659876e1a2cf019c55e419adab195 (patch)
tree63b9eb849574b723fc33973d55eb3b22ccd084f2
parent341774fe6ccdc0fe42fb79a4ed642e78237da428 (diff)
downloadfocaccia-qemu-439c5e02d59659876e1a2cf019c55e419adab195.tar.gz
focaccia-qemu-439c5e02d59659876e1a2cf019c55e419adab195.zip
rcu: add g_free_rcu
This simplifies calling g_free from an RCU callback.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--docs/rcu.txt11
-rw-r--r--include/qemu/rcu.h8
2 files changed, 15 insertions, 4 deletions
diff --git a/docs/rcu.txt b/docs/rcu.txt
index 61752b93ab..21ecb8106c 100644
--- a/docs/rcu.txt
+++ b/docs/rcu.txt
@@ -120,12 +120,15 @@ The core RCU API is small:
      void call_rcu(T *p,
                    void (*func)(T *p),
                    field-name);
+     void g_free_rcu(T *p,
+                     field-name);
 
-        call_rcu1 is typically used through this macro, in the common case
-        where the "struct rcu_head" is the first field in the struct.  In
-        the above case, one could have written simply:
+        call_rcu1 is typically used through these macro, in the common case
+        where the "struct rcu_head" is the first field in the struct.  If
+        the callback function is g_free, in particular, g_free_rcu can be
+        used.  In the above case, one could have written simply:
 
-            call_rcu(foo_reclaim, g_free, rcu);
+            g_free_rcu(foo_reclaim, rcu);
 
      typeof(*p) atomic_rcu_read(p);
 
diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h
index 068a279a79..506ab58eaf 100644
--- a/include/qemu/rcu.h
+++ b/include/qemu/rcu.h
@@ -140,6 +140,14 @@ extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func);
       }),                                                                \
       (RCUCBFunc *)(func))
 
+#define g_free_rcu(obj, field) \
+    call_rcu1(({                                                         \
+        char __attribute__((unused))                                     \
+            offset_must_be_zero[-offsetof(typeof(*(obj)), field)];       \
+        &(obj)->field;                                                   \
+      }),                                                                \
+      (RCUCBFunc *)g_free);
+
 #ifdef __cplusplus
 }
 #endif