Generalise locking init code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/main.c b/main.c
index 51cfdb3..585d21f 100644
--- a/main.c
+++ b/main.c
@@ -5871,16 +5871,10 @@ int main (int argc, char *argv[])
if (unlikely(curl_global_init(CURL_GLOBAL_ALL)))
quit(1, "Failed to curl_global_init");
- if (unlikely(pthread_mutex_init(&hash_lock, NULL)))
- quit(1, "Failed to pthread_mutex_init");
- if (unlikely(pthread_mutex_init(&qd_lock, NULL)))
- quit(1, "Failed to pthread_mutex_init");
- if (unlikely(pthread_mutex_init(&curses_lock, NULL)))
- quit(1, "Failed to pthread_mutex_init");
- if (unlikely(pthread_mutex_init(&control_lock, NULL)))
- quit(1, "Failed to pthread_mutex_init");
- if (unlikely(pthread_rwlock_init(&blk_lock, NULL)))
- quit(1, "Failed to pthread_rwlock_init");
+ mutex_init(&hash_lock);
+ mutex_init(&curses_lock);
+ mutex_init(&control_lock);
+ rwlock_init(&blk_lock);
sprintf(packagename, "%s %s", PACKAGE, VERSION);
diff --git a/miner.h b/miner.h
index 79f7ac1..a21de5f 100644
--- a/miner.h
+++ b/miner.h
@@ -389,6 +389,18 @@ static inline void wr_unlock(pthread_rwlock_t *lock)
rw_unlock(lock);
}
+static inline void mutex_init(pthread_mutex_t *lock)
+{
+ if (unlikely(pthread_mutex_init(lock, NULL)))
+ quit(1, "Failed to pthread_mutex_init");
+}
+
+static inline void rwlock_init(pthread_rwlock_t *lock)
+{
+ if (unlikely(pthread_rwlock_init(lock, NULL)))
+ quit(1, "Failed to pthread_rwlock_init");
+}
+
struct pool;
extern bool opt_debug;