From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liu Ping Fan Subject: [PATCH 14/15] qom: object_unref call reclaimer Date: Wed, 8 Aug 2012 14:25:55 +0800 Message-ID: <1344407156-25562-15-git-send-email-qemulist@gmail.com> References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> Cc: kvm@vger.kernel.org, Anthony Liguori , Avi Kivity , Jan Kiszka , Marcelo Tosatti , Stefan Hajnoczi , Paolo Bonzini , Blue Swirl , =?UTF-8?q?Andreas=20F=C3=A4rber?= , qemulist@gmail.com To: qemu-devel@nongnu.org Return-path: Received: from mail-ob0-f174.google.com ([209.85.214.174]:51936 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932126Ab2HHG1V (ORCPT ); Wed, 8 Aug 2012 02:27:21 -0400 Received: by mail-ob0-f174.google.com with SMTP id uo13so685038obb.19 for ; Tue, 07 Aug 2012 23:27:21 -0700 (PDT) In-Reply-To: <1344407156-25562-1-git-send-email-qemulist@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Liu Ping Fan iohandler/bh/timer may use DeviceState when its refcnt=0, postpone the reclaimer till they have done with it. Signed-off-by: Liu Ping Fan --- qom/object.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/qom/object.c b/qom/object.c index 822bdb7..1452b1b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -23,6 +23,8 @@ #include "qbool.h" #include "qint.h" #include "qstring.h" +#include "hw/qdev.h" +#include "qemu/reclaimer.h" #define MAX_INTERFACES 32 @@ -646,7 +648,12 @@ void object_unref(Object *obj) { g_assert(atomic_read(&obj->ref) > 0); if (atomic_dec_and_test(&obj->ref)) { - object_finalize(obj); + /* fixme, maybe introduce obj->finalze to make this more elegant */ + if (object_dynamic_cast(obj, TYPE_DEVICE) != NULL) { + qemu_reclaimer_enqueue(obj, object_finalize); + } else { + object_finalize(obj); + } } } -- 1.7.4.4