From patchwork Sun Nov 25 02:02:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v7,1/7] qom: apply atomic on object's refcount From: pingfan liu X-Patchwork-Id: 201504 Message-Id: <1353808984-22368-2-git-send-email-qemulist@gmail.com> To: qemu-devel@nongnu.org Cc: Peter Maydell , gleb@redhat.com, Jan Kiszka , Marcelo Tosatti , Anthony Liguori , Stefan Hajnoczi , Paolo Bonzini Date: Sun, 25 Nov 2012 10:02:58 +0800 From: Liu Ping Fan Signed-off-by: Liu Ping Fan --- qom/object.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..1a697b3 100644 --- a/qom/object.c +++ b/qom/object.c @@ -600,16 +600,15 @@ GSList *object_class_get_list(const char *implements_type, void object_ref(Object *obj) { - obj->ref++; + __sync_fetch_and_add(&obj->ref, 1); } 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 (__sync_fetch_and_sub(&obj->ref, 1) == 1) { object_finalize(obj); } }