summaryrefslogtreecommitdiffstats
path: root/src/util.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-08-12 09:19:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-08-12 09:19:14 +0000
commitecc5838aff97659dd679f03edc8838205f868848 (patch)
tree85848124743d10e50adce2e36e3566b3d37b4ce7 /src/util.h
parentAdding upstream version 2.6.0. (diff)
downloaddnsperf-ecc5838aff97659dd679f03edc8838205f868848.tar.xz
dnsperf-ecc5838aff97659dd679f03edc8838205f868848.zip
Adding upstream version 2.7.0.upstream/2.7.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h14
1 files changed, 14 insertions, 0 deletions
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 <stdbool.h>
#include <string.h>
#include <sys/time.h>
+#include <errno.h>
#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)); \