From b6d97fef4669d07c108b130ea882f19a737d2ae9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 12 Aug 2021 11:19:20 +0200 Subject: Merging upstream version 2.7.0. Signed-off-by: Daniel Baumann --- src/util.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 245c984..1b83487 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,7 @@ #include #include #include +#include #define MILLION ((uint64_t)1000000) @@ -76,6 +77,19 @@ } \ } while (0) +static inline int PERF_TRYLOCK(pthread_mutex_t* mutex) +{ + int __n = pthread_mutex_trylock(mutex); + if (__n == EBUSY) { + return 1; + } + if (__n != 0) { + char __s[256]; + perf_log_fatal("pthread_mutex_lock failed: %s", perf_strerror_r(__n, __s, sizeof(__s))); + } + return 0; +} + #define PERF_UNLOCK(mutex) \ do { \ int __n = pthread_mutex_unlock((mutex)); \ -- cgit v1.2.3