]> git.itanic.dy.fi Git - rrdd/commitdiff
Refactor mutex code to utils.h
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 22 Aug 2019 18:26:31 +0000 (21:26 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 22 Aug 2019 18:26:31 +0000 (21:26 +0300)
This is more useful here as it does not exactly belong to process
handling.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
process.h
utils.h

index 2d58565ff883d5a9b80281bd73d7c127467254b9..0971a7126840fddc2b3c3a593e19645a7c8efcb3 100644 (file)
--- a/process.h
+++ b/process.h
@@ -9,7 +9,6 @@
 #include <error.h>
 #include <errno.h>
 #include <stdint.h>
-#include <pthread.h>
 
 struct event_handler;
 
@@ -23,15 +22,6 @@ struct event_handler {
        char *name;
 };
 
-struct mutex {
-       pthread_mutex_t lock;
-       int line;
-       char *file;
-       char owner_name[16];
-       time_t lock_time;
-       char *name;
-};
-
 int register_event_handler(struct event_handler *handler);
 
 int init_jobcontrol(int max_jobs_requested);
@@ -44,14 +34,6 @@ int run_piped(const char *cmd, char *const argv[],
 int run_piped_stream(const char *cmd, char *const argv[],
                     FILE **stdinf, FILE **stdoutf, FILE **stderrf);
 
-void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
-int _mutex_lock(struct mutex *lock, char *file, int line);
-int _mutex_unlock(struct mutex *lock);
-
-#define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
-#define mutex_unlock(lock) _mutex_unlock(lock)
-#define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
-
 enum {
        WORK_PRIORITY_HIGH,
        WORK_PRIORITY_LOW,
diff --git a/utils.h b/utils.h
index 40c212d93b4c67a90f5f36cc128aecb9007d7f28..cdb082f3b5ea1fcfe7f495742d5f4a56c23c5f01 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -1,9 +1,28 @@
 #ifndef _UTILS_H_
 #define _UTILS_H_
 
+#include <pthread.h>
+
 #define min(a, b) ((a) < (b) ? (a) : (b))
 #define max(a,b) (a) < (b) ? (b) : (a)
 
 #define ARRAY_SIZE(a) (sizeof(a) / (sizeof((a)[0])))
 
+struct mutex {
+       pthread_mutex_t lock;
+       int line;
+       char *file;
+       char owner_name[16];
+       time_t lock_time;
+       char *name;
+};
+
+void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
+int _mutex_lock(struct mutex *lock, char *file, int line);
+int _mutex_unlock(struct mutex *lock);
+
+#define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
+#define mutex_unlock(lock) _mutex_unlock(lock)
+#define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
+
 #endif