提交 f08c03f3 编写于 作者: J Jan Kiszka 提交者: Paolo Bonzini

qom: Use atomics for object refcounting

Object reference counts will soon be changed outside the BQL. So we need
to use atomics in object_ref/unref.

Based on a patch by Liu Ping Fan.
Signed-off-by: NLiu Ping Fan <qemulist@gmail.com>
Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 856d7245
......@@ -683,16 +683,15 @@ GSList *object_class_get_list(const char *implements_type,
void object_ref(Object *obj)
{
obj->ref++;
atomic_inc(&obj->ref);
}
void object_unref(Object *obj)
{
g_assert(obj->ref > 0);
obj->ref--;
/* parent always holds a reference to its children */
if (obj->ref == 0) {
if (atomic_fetch_dec(&obj->ref) == 1) {
object_finalize(obj);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册