Bugfix: Use a mutex to control non-curses output Without this, there is no guarantee writes won't overlap (and it happens quite a bit on Windows with the bitforce driver)
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/cgminer.c b/cgminer.c
index 2062397..87e23f8 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -164,7 +164,7 @@ static int total_threads;
static pthread_mutex_t hash_lock;
static pthread_mutex_t qd_lock;
static pthread_mutex_t *stgd_lock;
-static pthread_mutex_t curses_lock;
+pthread_mutex_t console_lock;
static pthread_mutex_t ch_lock;
static pthread_rwlock_t blk_lock;
@@ -1323,12 +1323,12 @@ struct cgpu_info *cpus;
#ifdef HAVE_CURSES
static inline void unlock_curses(void)
{
- mutex_unlock(&curses_lock);
+ mutex_unlock(&console_lock);
}
static inline void lock_curses(void)
{
- mutex_lock(&curses_lock);
+ mutex_lock(&console_lock);
}
static bool curses_active_locked(void)
@@ -5056,9 +5056,7 @@ int main(int argc, char *argv[])
mutex_init(&hash_lock);
mutex_init(&qd_lock);
-#ifdef HAVE_CURSES
- mutex_init(&curses_lock);
-#endif
+ mutex_init(&console_lock);
mutex_init(&control_lock);
mutex_init(&sharelog_lock);
mutex_init(&ch_lock);
diff --git a/logging.c b/logging.c
index 26e0196..47d1970 100644
--- a/logging.c
+++ b/logging.c
@@ -34,7 +34,9 @@ static void my_log_curses(__maybe_unused int prio, char *f, va_list ap)
strcpy(f + len - 1, " \n");
+ mutex_lock(&console_lock);
vprintf(f, ap);
+ mutex_unlock(&console_lock);
}
}
diff --git a/miner.h b/miner.h
index 6aaa314..3f55670 100644
--- a/miner.h
+++ b/miner.h
@@ -576,6 +576,8 @@ extern bool fulltest(const unsigned char *hash, const unsigned char *target);
extern int opt_scantime;
+extern pthread_mutex_t console_lock;
+
extern pthread_mutex_t restart_lock;
extern pthread_cond_t restart_cond;