Moved pthread mutex inits up, due to applog using a mutex causing a crash. Added Win32 compatability to opt.c.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/ccan/opt/opt.c b/ccan/opt/opt.c
index 827109e..e3ccdbd 100644
--- a/ccan/opt/opt.c
+++ b/ccan/opt/opt.c
@@ -3,7 +3,16 @@
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
-#include <err.h>
+
+#ifndef WIN32
+ #include <err.h>
+#else
+ #define errx(status, fmt, ...) { \
+ fprintf(stderr, fmt, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ exit(status); }
+#endif
+
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
@@ -191,11 +200,20 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...))
{
int ret;
unsigned offset = 0;
+
+ #ifdef WIN32
+ char *original_argv0 = argv[0];
+ argv[0] = (char*)basename(argv[0]);
+ #endif
/* This helps opt_usage. */
opt_argv0 = argv[0];
while ((ret = parse_one(argc, argv, &offset, errlog)) == 1);
+
+ #ifdef WIN32
+ argv[0] = original_argv0;
+ #endif
/* parse_one returns 0 on finish, -1 on error */
return (ret == 0);
diff --git a/main.c b/main.c
index e468ae1..efc1c53 100644
--- a/main.c
+++ b/main.c
@@ -1624,6 +1624,16 @@ int main (int argc, char *argv[])
char name[32];
struct cgpu_info *gpus = NULL, *cpus = NULL;
+ 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)))
+ return 1;
+ if (unlikely(pthread_mutex_init(&stgd_lock, NULL)))
+ return 1;
+
+
#ifdef WIN32
opt_n_threads = num_processors = 1;
#else
@@ -1671,15 +1681,6 @@ int main (int argc, char *argv[])
sprintf(rpc_userpass, "%s:%s", rpc_user, rpc_pass);
}
- 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)))
- return 1;
- if (unlikely(pthread_mutex_init(&stgd_lock, NULL)))
- return 1;
-
if (unlikely(curl_global_init(CURL_GLOBAL_ALL)))
return 1;
#ifdef HAVE_SYSLOG_H