From 69ab3a8cf403d34c8659935eee2d75fb60a8fee3 Mon Sep 17 00:00:00 2001 From: ystarnaud Date: Wed, 2 Jul 2014 15:09:31 -0400 Subject: [PATCH] Changed the way hard restart is done for better compatibility with windows pthread. --- sgminer.c | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/sgminer.c b/sgminer.c index 9f8715ee..586c3f96 100644 --- a/sgminer.c +++ b/sgminer.c @@ -6561,29 +6561,10 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) n_threads = mining_threads; #endif - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - if (unlikely(pthread_create(&restart_thr, NULL, restart_mining_threads_thread, (void *) (intptr_t) n_threads))) quit(1, "restart_mining_threads create thread failed"); - sleep(60); - - #ifdef __TEMP_ALGO_SWITCH_FIX__ - //if restart thread is done, then abort... - if(!thread_fix_search(restart_thr)) - { - applog(LOG_DEBUG, "thread %d not found in fix list, don't exit sgminer", restart_thr); - pthread_cancel(restart_thr); - - mutex_lock(&algo_switch_wait_lock); - algo_switch_n = 0; - pthread_cond_broadcast(&algo_switch_wait_cond); - mutex_unlock(&algo_switch_wait_lock); - return; - } - #endif /* __TEMP_ALGO_SWITCH_FIX__ */ - - quit(1, "thread was not cancelled in 60 seconds after restart_mining_threads"); + // go wait with the other threads... } else { @@ -6594,22 +6575,24 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) mutex_unlock(&algo_switch_wait_lock); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + // no need to wait, exit + return; } } else - { mutex_unlock(&algo_switch_lock); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - // Wait for signal to start working again - mutex_lock(&algo_switch_wait_lock); - // Set cleanup instructions in the event that the thread is cancelled - pthread_cleanup_push(mutex_unlock_cleanup_handler, (void *)&algo_switch_wait_lock); - while(algo_switch_n > 0) - pthread_cond_wait(&algo_switch_wait_cond, &algo_switch_wait_lock); - // Non-zero argument will execute the cleanup handler after popping it - pthread_cleanup_pop(1); - } + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + // Set cleanup instructions in the event that the thread is cancelled + pthread_cleanup_push(mutex_unlock_cleanup_handler, (void *)&algo_switch_wait_lock); + // Wait for signal to start working again + mutex_lock(&algo_switch_wait_lock); + while(algo_switch_n > 0) + pthread_cond_wait(&algo_switch_wait_cond, &algo_switch_wait_lock); + // Non-zero argument will execute the cleanup handler after popping it + pthread_cleanup_pop(1); } struct work *get_work(struct thr_info *thr, const int thr_id)