提交 439c5e02 编写于 作者: P Paolo Bonzini

rcu: add g_free_rcu

This simplifies calling g_free from an RCU callback.
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 341774fe
...@@ -120,12 +120,15 @@ The core RCU API is small: ...@@ -120,12 +120,15 @@ The core RCU API is small:
void call_rcu(T *p, void call_rcu(T *p,
void (*func)(T *p), void (*func)(T *p),
field-name); field-name);
void g_free_rcu(T *p,
field-name);
call_rcu1 is typically used through this macro, in the common case call_rcu1 is typically used through these macro, in the common case
where the "struct rcu_head" is the first field in the struct. In where the "struct rcu_head" is the first field in the struct. If
the above case, one could have written simply: 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); typeof(*p) atomic_rcu_read(p);
......
...@@ -140,6 +140,14 @@ extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func); ...@@ -140,6 +140,14 @@ extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func);
}), \ }), \
(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 #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册