]> git.alsa-project.org Git - alsa-lib.git/commitdiff
core: add convenience macros to local.h
authorLiam Girdwood <liam.r.girdwood@linux.intel.com>
Tue, 11 Aug 2015 17:23:15 +0000 (18:23 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 12 Aug 2015 14:39:27 +0000 (16:39 +0200)
Move ARRAY_SIZE() from tplg_local.h to local.h and add container_of()
macro to local.h. Both macros are generic but are initially used by
topology.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/local.h
src/topology/tplg_local.h

index 660081638a1c0878277043b7fd5b9a9cfb8fb1e9..b429f5d0094cb2865da451443e2b8aae1dfa40b6 100644 (file)
@@ -350,4 +350,11 @@ int snd_config_search_alias_hooks(snd_config_t *config,
 
 int _snd_conf_generic_id(const char *id);
 
+/* convenience macros */
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+       (type *)( (char *)__mptr - offsetof(type,member) );})
+
 #endif
index febc1772fd04aefad886daee65d0f4abf473824c..3982cc70dce58b1fc46ee77c3d1b3dbe0aededa7 100644 (file)
@@ -32,7 +32,6 @@
 #define MAX_FILE               256
 #define TPLG_MAX_PRIV_SIZE     (1024 * 128)
 #define ALSA_TPLG_DIR  ALSA_CONFIG_DIR "/topology"
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 
 /** The name of the environment variable containing the tplg directory */
 #define ALSA_CONFIG_TPLG_VAR "ALSA_CONFIG_TPLG"