]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
rcu: add g_free_rcu
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 11 Feb 2015 14:00:12 +0000 (15:00 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Feb 2015 16:30:19 +0000 (17:30 +0100)
This simplifies calling g_free from an RCU callback.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
docs/rcu.txt
include/qemu/rcu.h

index 61752b93ab3e625e2d933d0e87d31b0ba872d2f4..21ecb8106cdbdb3c8ff6434646a3a2b56f7db295 100644 (file)
@@ -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);
 
index 068a279a797f6cdec715cc936f8dc437605bd4fb..506ab58eaf0fda84d3d9c3e22e27c8eaddd11e5c 100644 (file)
@@ -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