Get rid of the flaky time_lock and use the thread safe localtime_r instead.
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
diff --git a/main.c b/main.c
index be69cba..aad34ea 100644
--- a/main.c
+++ b/main.c
@@ -153,7 +153,6 @@ static int work_thr_id;
int longpoll_thr_id;
static int stage_thr_id;
struct work_restart *work_restart = NULL;
-pthread_mutex_t time_lock;
static pthread_mutex_t hash_lock;
static pthread_mutex_t qd_lock;
static pthread_mutex_t stgd_lock;
@@ -1740,8 +1739,6 @@ int main (int argc, char *argv[])
unsigned int i, j = 0;
char name[32];
- if (unlikely(pthread_mutex_init(&time_lock, NULL)))
- return 1;
if (unlikely(pthread_mutex_init(&hash_lock, NULL)))
return 1;
if (unlikely(pthread_mutex_init(&qd_lock, NULL)))
diff --git a/miner.h b/miner.h
index 1d4e1b2..c961e32 100644
--- a/miner.h
+++ b/miner.h
@@ -226,7 +226,6 @@ struct work_restart {
char padding[128 - sizeof(unsigned long)];
};
-extern pthread_mutex_t time_lock;
extern int hw_errors;
extern bool use_syslog;
extern struct thr_info *thr_info;
diff --git a/util.c b/util.c
index d3cc6fa..68118e8 100644
--- a/util.c
+++ b/util.c
@@ -71,14 +71,11 @@ void vapplog(int prio, const char *fmt, va_list ap)
char *f;
int len;
struct timeval tv = { };
- struct tm tm, *tm_p;
+ struct tm tm;
gettimeofday(&tv, NULL);
- pthread_mutex_lock(&time_lock);
- tm_p = localtime(&tv.tv_sec);
- memcpy(&tm, tm_p, sizeof(tm));
- pthread_mutex_unlock(&time_lock);
+ localtime_r(&tv.tv_sec, &tm);
len = 40 + strlen(fmt) + 2;
f = alloca(len);