]> git.itanic.dy.fi Git - rrdd/blobdiff - process.c
process: Add debug wrappers for pthread mutex operations
[rrdd] / process.c
index d6ed65199b97a5e4a0658ec8b408b2140667a942..ad47196501ecc3a70b773f252e170ba2dfabe9bb 100644 (file)
--- a/process.c
+++ b/process.c
@@ -1,4 +1,3 @@
-#define _GNU_SOURCE
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/select.h>
@@ -702,3 +701,38 @@ int register_event_handler(struct event_handler *handler)
 
        return 0;
 }
+
+void _mutex_lock_acquired(struct mutex *lock, char *file, int line)
+{
+       lock->line = line;
+       lock->file = file;
+}
+
+int _mutex_lock(struct mutex *lock, char *file, int line)
+{
+       int ret = 0;
+
+       if (!pthread_mutex_trylock(&lock->lock))
+               goto out_lock;
+
+       pr_info("Lock contention on lock %s on %s:%d\n",
+               lock->name, lock->file, lock->line);
+
+       ret = pthread_mutex_lock(&lock->lock);
+       if (ret)
+               pr_err("Acquirin lock %s failed: %m, acquired %s:%d\n",
+                       lock->name, lock->file, lock->line);
+
+out_lock:
+       _mutex_lock_acquired(lock, file, line);
+       return ret;
+}
+
+int _mutex_unlock(struct mutex *lock)
+{
+       lock->line = 0;
+       lock->file = NULL;
+       pthread_mutex_unlock(&lock->lock);
+
+       return 0;
+}