summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2013-07-02 11:36:39 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2013-07-04 17:42:49 +0200
commitf08c03f3c404e85a2b81890191ccb48dc1ecc157 (patch)
treed5434b5d7304f9da641af763db654d032fa500b3
parent856d72454f03aea26fd61c728762ef9cd1d71512 (diff)
downloadqemu-f08c03f3c404e85a2b81890191ccb48dc1ecc157.zip
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: Liu Ping Fan <qemulist@gmail.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--qom/object.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/qom/object.c b/qom/object.c
index 803b94bb66..cbd7e86033 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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);
}
}