From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, avi@redhat.com
Subject: [Qemu-devel] [PATCH 01/29] Introduce QObject
Date: Thu, 13 Aug 2009 10:50:00 -0300 [thread overview]
Message-ID: <1250171428-29308-2-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com>
This commit introduces the qobject.h header file, it contains
basic QObject definitions and helper macros.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
qobject.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 95 insertions(+), 0 deletions(-)
create mode 100644 qobject.h
diff --git a/qobject.h b/qobject.h
new file mode 100644
index 0000000..467f258
--- /dev/null
+++ b/qobject.h
@@ -0,0 +1,95 @@
+/*
+ * QEMU Object Model.
+ *
+ * Based on ideas by Avi Kivity <avi@redhat.com>
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ * Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ * QObject Reference Counts
+ * ------------------------
+ *
+ * The concept of reference counting used here is the same of Python, ie,
+ * 'ownership of references'.
+ *
+ * Basic terminology:
+ *
+ * - Owning a reference: means being responsible for calling qobject_decref()
+ * when the reference is no longer needed
+ *
+ * - New reference: means that the caller is now the owner of a reference,
+ * for example, if you call a function that returns a 'new reference' you
+ * must call qobject_decref() when you are done
+ *
+ * - Borrowing a reference: nothing needs to be done, you are not the
+ * owner of the reference
+ *
+ * - Stealing a reference: when you pass a reference to a function that
+ * "steals a reference' this function assumes that it now owns that
+ * reference
+ */
+#ifndef QOBJECT_H
+#define QOBJECT_H
+
+#include <stddef.h>
+
+typedef enum {
+ QTYPE_NONE,
+} qtype_code;
+
+struct QObject;
+
+typedef struct QType {
+ qtype_code code;
+ void (*destroy)(struct QObject *);
+} QType;
+
+typedef struct QObject {
+ const QType *type;
+ size_t refcnt;
+} QObject;
+
+// Get the QObject part of a type
+#define QOBJECT(obj) (&obj->base)
+
+/**
+ * qobject_init(): Initialize a QObject to default values
+ */
+static inline void qobject_init(QObject *obj, const QType *type)
+{
+ obj->refcnt = 1;
+ obj->type = type;
+}
+
+/**
+ * qobject_incref(): Increment QObject's reference count
+ */
+static inline void qobject_incref(QObject *obj)
+{
+ obj->refcnt++;
+}
+
+/**
+ * qobject_decref(): Decrement QObject's reference count, deallocate
+ * when it reaches zero
+ */
+static inline void qobject_decref(QObject *obj)
+{
+ if (--obj->refcnt == 0)
+ obj->type->destroy(obj);
+}
+
+/**
+ * qobject_type(): Return the QObject's type
+ */
+static inline qtype_code qobject_type(const QObject *obj)
+{
+ return obj->type->code;
+}
+
+#endif /* QOBJECT_H */
--
1.6.4.67.gea5b1
next prev parent reply other threads:[~2009-08-13 13:51 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-13 13:49 [Qemu-devel] [PATCH v0 00/29] QMonitor Luiz Capitulino
2009-08-13 13:50 ` Luiz Capitulino [this message]
2009-08-13 13:50 ` [Qemu-devel] [PATCH 02/29] Introduce QInt Luiz Capitulino
2009-08-13 13:55 ` [Qemu-devel] " Avi Kivity
2009-08-13 14:16 ` Luiz Capitulino
2009-08-13 14:43 ` Avi Kivity
2009-08-13 13:50 ` [Qemu-devel] [PATCH 03/29] Introduce QString Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 04/29] Introduce QDict Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 05/29] Add wrappers to functions used by the Monitor Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 06/29] monitor: New format for handlers argument types Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 07/29] monitor: Setup a QDict with arguments to handlers Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 08/29] monitor: Export QDict header Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 09/29] monitor: Port handler_0 to use QDict Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 10/29] monitor: Port handler_1 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 11/29] monitor: Port handler_2 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 12/29] monitor: Port handler_3 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 13/29] monitor: Port handler_4 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 14/29] monitor: Port handler_5 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 15/29] monitor: Port handler_6 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 16/29] monitor: Port handler_7 " Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 17/29] monitor: Drop handler_8 and handler_9 Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 18/29] monitor: Port handler_10 to use QDict Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 19/29] monitor: Split monitor_handle_command() Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 20/29] monitor: Drop unused macros Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 21/29] monitor: Drop str_allocated[] Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 22/29] monitor: Drop args[] handling code Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 23/29] monitor: fail when 'i' type is greater than 32-bit Luiz Capitulino
2009-08-13 13:59 ` [Qemu-devel] " Avi Kivity
2009-08-13 14:18 ` Luiz Capitulino
2009-08-13 14:43 ` Avi Kivity
2009-08-13 13:50 ` [Qemu-devel] [PATCH 24/29] monitor: Update supported types documentation Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 25/29] Add check support Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 26/29] Introduce QInt unit-tests Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 27/29] Introduce QString unit-tests Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 28/29] Introduce QDict test data file Luiz Capitulino
2009-08-13 13:50 ` [Qemu-devel] [PATCH 29/29] Introduce QDict unit-tests Luiz Capitulino
-- strict thread matches above, loose matches on Subject: below --
2009-08-19 23:07 [Qemu-devel] [PATCH v1 00/29] QMonitor Luiz Capitulino
2009-08-19 23:07 ` [Qemu-devel] [PATCH 01/29] Introduce QObject Luiz Capitulino
2009-08-26 17:05 [Qemu-devel] [PATCH v2 00/29] QMonitor Luiz Capitulino
2009-08-26 17:05 ` [Qemu-devel] [PATCH 01/29] Introduce QObject Luiz Capitulino
2009-08-28 18:27 [Qemu-devel] [PATCH v3 00/29] QMonitor Luiz Capitulino
2009-08-28 18:27 ` [Qemu-devel] [PATCH 01/29] Introduce QObject Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1250171428-29308-2-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).