From 7528a95fe1d3b8895158837155268b68eb2f1f65 Mon Sep 17 00:00:00 2001 From: pooler Date: Sun, 9 Jun 2013 18:21:39 +0200 Subject: [PATCH] Perform global libcurl initialization curl_easy_init() is not thread-safe unless curl_global_init() has already been called. It seems that SSL initialization is slow on Windows, so only do that if the mining server has to be accessed via HTTPS. Thanks to @martinwguy for pointing this out. --- cpu-miner.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/cpu-miner.c b/cpu-miner.c index 858e903..1ad105d 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -1244,6 +1244,7 @@ void signal_handler(int sig) int main(int argc, char *argv[]) { struct thr_info *thr; + long flags; int i; rpc_url = strdup(DEF_RPC_URL); @@ -1253,6 +1254,20 @@ int main(int argc, char *argv[]) /* parse command line */ parse_cmdline(argc, argv); + pthread_mutex_init(&applog_lock, NULL); + pthread_mutex_init(&stats_lock, NULL); + pthread_mutex_init(&g_work_lock, NULL); + pthread_mutex_init(&stratum.sock_lock, NULL); + pthread_mutex_init(&stratum.work_lock, NULL); + + flags = strncmp(rpc_url, "https:", 6) + ? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL) + : CURL_GLOBAL_ALL; + if (curl_global_init(flags)) { + applog(LOG_ERR, "CURL initialization failed"); + return 1; + } + #ifndef WIN32 if (opt_background) { i = fork(); @@ -1270,12 +1285,6 @@ int main(int argc, char *argv[]) } #endif - pthread_mutex_init(&applog_lock, NULL); - pthread_mutex_init(&stats_lock, NULL); - pthread_mutex_init(&g_work_lock, NULL); - pthread_mutex_init(&stratum.sock_lock, NULL); - pthread_mutex_init(&stratum.work_lock, NULL); - #if defined(WIN32) SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo);