This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


[Xen-devel] [PATCH 03/11] add container_of() macro to osdep.h

To: qemu-devel@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 03/11] add container_of() macro to osdep.h
From: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Date: Mon, 11 Aug 2008 14:32:42 +0200
Cc: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Delivery-date: Mon, 11 Aug 2008 05:34:30 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1218457970-11707-1-git-send-email-kraxel@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1218457970-11707-1-git-send-email-kraxel@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
>From linux kernel sources, xen bits will use it, put it
into a place where others can see and use it too ;)

Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
 osdep.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/osdep.h b/osdep.h
index a32242e..b69ce2e 100644
--- a/osdep.h
+++ b/osdep.h
@@ -19,6 +19,10 @@
 #define unlikely(x)   __builtin_expect(!!(x), 0)
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+        (type *)( (char *)__mptr - offsetof(type,member) );})
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))

Xen-devel mailing list