Add lttng_ust_ prefix before objd_unref
[lttng-ust.git] / include / ust / core.h
index d1fdb2dfdb2c7faa9eb6805a37b6f99bace22a22..4e75c515e708893db275adb7bbf699046d9dd429 100644 (file)
@@ -3,11 +3,12 @@
 
 /*
  * Copyright (C) 2010  Pierre-Marc Fournier
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * License as published by the Free Software Foundation; version 2.1 of
+ * the License.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,9 +23,7 @@
 #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)
+#include <urcu/compiler.h>
 
 /* ARRAYS */
 
@@ -44,7 +43,7 @@
 /* ERROR OPS */
 #define MAX_ERRNO      4095
 
-#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
+#define IS_ERR_VALUE(x) caa_unlikely((x) >= (unsigned long)-MAX_ERRNO)
 
 static inline void *ERR_PTR(long error)
 {
@@ -138,4 +137,35 @@ static __inline__ int get_count_order(unsigned int count)
 #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 (caa_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.024167 seconds and 4 git commands to generate.