implement ring buffer clients
[lttng-ust.git] / include / ust / core.h
index eee405dd4c27a46d743eecb625daaed5c144f065..b9f5b9793887a27cb433444f26f8399f1ef60ca9 100644 (file)
@@ -1,4 +1,8 @@
-/* Copyright (C) 2010  Pierre-Marc Fournier
+#ifndef UST_CORE_H
+#define UST_CORE_H
+
+/*
+ * Copyright (C) 2010  Pierre-Marc Fournier
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#ifndef UST_CORE_H
-#define UST_CORE_H
-
 #include <sys/types.h>
 #include <ust/config.h>
+#include <urcu/arch.h>
 
 #define likely(x)      __builtin_expect(!!(x), 1)
 #define unlikely(x)    __builtin_expect(!!(x), 0)
@@ -82,7 +84,25 @@ static inline long IS_ERR(const void *ptr)
 
 /* MALLOCATION */
 
-#define zmalloc(s) calloc(1, s)
+#include <stdlib.h>
+
+static inline
+void *zmalloc(size_t len)
+{
+       return calloc(1, len);
+}
+
+static inline
+void *malloc_align(size_t len)
+{
+       return malloc(ALIGN(len, CAA_CACHE_LINE_SIZE));
+}
+
+static inline
+void *zmalloc_align(size_t len)
+{
+       return calloc(1, ALIGN(len, CAA_CACHE_LINE_SIZE));
+}
 
 /* MATH */
 
@@ -110,4 +130,43 @@ static __inline__ int get_count_order(unsigned int count)
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
         (type *)( (char *)__mptr - offsetof(type,member) );})
 
+#ifndef inline_memcpy
+#define inline_memcpy memcpy
+#endif
+
+#ifndef __same_type
+#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+#endif
+
+#ifndef UST_VALGRIND
+
+static __inline__ int ust_get_cpu(void)
+{
+       int cpu;
+
+       cpu = sched_getcpu();
+       if (likely(cpu >= 0))
+               return cpu;
+       /*
+        * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback.
+        */
+       return 0;
+}
+
+#else  /* #else #ifndef UST_VALGRIND */
+
+static __inline__ int ust_get_cpu(void)
+{
+       /*
+        * Valgrind does not support the sched_getcpu() vsyscall.
+        * It causes it to detect a segfault in the program and stop it.
+        * So if we want to check libust with valgrind, we have to refrain
+        * from using this call. TODO: it would probably be better to return
+        * other values too, to better test it.
+        */
+       return 0;
+}
+
+#endif /* #else #ifndef UST_VALGRIND */
+
 #endif /* UST_CORE_H */
This page took 0.024924 seconds and 4 git commands to generate.