From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f193.google.com (mail-wj0-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id BADC610A7 for ; Fri, 23 Dec 2016 16:58:29 +0100 (CET) Received: by mail-wj0-f193.google.com with SMTP id qs7so3091535wjc.1 for ; Fri, 23 Dec 2016 07:58:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=T+rKJB7dzdFzk0/b3hpq3AO6pmHz3NP5abxSAH4N4w0=; b=ixZd9/nLa0hj3OJFZCkm5PUujukPF7LaxYsmyDEuP3SQeflrngf/+lBESv+LgERaaY cDwcjLLghKIV2JF9L+HU3eKSTHpFZMrMTE+RcP0KkZmTPSMPnGNn3h2RMKdHAPqMBwwS BZWWqReyeDdameXx5WpdwkwdBhWAktdsrQParsASOtWiuhXud9uHrt/Ixsm3Acj1r//9 +mInZ1VZMMUG7LaVuJvvc3NaOwpWxA32W37kRr/eDq8R4JmcPSE9EqP5T3mjJAEjPsPt JQwd8M+58UWyO0yWPaMPY9LSPvgP/SnzSjlU53MYIZwaK7FuhCA72Ka+yNXCjMQz6SnG MD/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=T+rKJB7dzdFzk0/b3hpq3AO6pmHz3NP5abxSAH4N4w0=; b=sFEs28u1b4sbW/i5Vce8N+rEpS2ZXq3p7dUniCw/PabyCH5c8sAqEvXA4TFO2Iivzl 32wnE/d4ZwbIM0MbZRBIaI5sJmNHrIM2/ZKUmNBYDtWfhEwS01jqqvyBbTb+UWwIOiGt PtTh+QPPGQxlbVr+MIbW19oh+0JJHfCMBMCTB+gorbuWei64qn5bkV7ool1fF9VLvsXI +ER0LFhF675q1aNcddGQHM/pxB8pPaibV8qzUnxlojPmj9y/rvcS7cuGzFbVvI6p0Zbk EOW0iIAkqe2bn/0MqSu0x3Q5k6xGvoP4JywjnvNlKwAox9+dmmSQN4CiKmYKKa2F3LMB Ws6g== X-Gm-Message-State: AIkVDXL7v0cHOckZ6yj6zO2YJtGJ1DI1V0NtG5gIieM+BtxmyAU52ac2krOa2ABNUUGdQQ== X-Received: by 10.194.98.208 with SMTP id ek16mr16145213wjb.94.1482508709306; Fri, 23 Dec 2016 07:58:29 -0800 (PST) Received: from weierstrass.local.net ([91.200.109.169]) by smtp.gmail.com with ESMTPSA id jm6sm41027072wjb.27.2016.12.23.07.58.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Dec 2016 07:58:28 -0800 (PST) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: shreyansh.jain@nxp.com, david.marchand@6wind.com, stephen@networkplumber.org, Jan Viktorin Date: Fri, 23 Dec 2016 16:57:52 +0100 Message-Id: <1482508691-11408-2-git-send-email-jblunck@infradead.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482508691-11408-1-git-send-email-jblunck@infradead.org> References: <1482508691-11408-1-git-send-email-jblunck@infradead.org> In-Reply-To: <1482332986-7599-1-git-send-email-jblunck@infradead.org> References: <1482332986-7599-1-git-send-email-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v5 01/20] eal: define container_of macro X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2016 15:58:29 -0000 This macro is based on Jan Viktorin's original patch but also checks the type of the passed pointer against the type of the member. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain [jblunck@infradead.org: add type checking and __extension__] Signed-off-by: Jan Blunck --- lib/librte_eal/common/include/rte_common.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index db5ac91..8dda3e2 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -331,6 +331,26 @@ rte_bsf32(uint32_t v) #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) #endif +/** + * Return pointer to the wrapping struct instance. + * + * Example: + * + * struct wrapper { + * ... + * struct child c; + * ... + * }; + * + * struct child *x = obtain(...); + * struct wrapper *w = container_of(x, struct wrapper, c); + */ +#ifndef container_of +#define container_of(ptr, type, member) __extension__ ({ \ + typeof(((type *)0)->member) *_ptr = (ptr); \ + (type *)(((char *)_ptr) - offsetof(type, member)); }) +#endif + #define _RTE_STR(x) #x /** Take a macro value and get a string version of it */ #define RTE_STR(x) _RTE_STR(x) -- 2.7.4