From 6604a3f0f27095f4b862e286944a3e5c4b27e600 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Thu, 22 Aug 2019 21:26:31 +0300 Subject: [PATCH] Refactor mutex code to utils.h This is more useful here as it does not exactly belong to process handling. Signed-off-by: Timo Kokkonen --- process.h | 18 ------------------ utils.h | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/process.h b/process.h index 2d58565..0971a71 100644 --- a/process.h +++ b/process.h @@ -9,7 +9,6 @@ #include #include #include -#include 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 40c212d..cdb082f 100644 --- a/utils.h +++ b/utils.h @@ -1,9 +1,28 @@ #ifndef _UTILS_H_ #define _UTILS_H_ +#include + #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 -- 2.44.0