Browse Source

Merge commit '15c1bc7' into bfgminer

Luke Dashjr 11 years ago
parent
commit
5bd214240c
2 changed files with 24 additions and 56 deletions
  1. 23 5
      miner.c
  2. 1 51
      util.c

+ 23 - 5
miner.c

@@ -9301,10 +9301,26 @@ static void pool_resus(struct pool *pool)
 		applog(LOG_INFO, "Pool %d %s alive", pool->pool_no, pool->rpc_url);
 }
 
+static
+void *cmd_idle_thread(void * const __maybe_unused userp)
+{
+	pthread_detach(pthread_self());
+	RenameThread("cmd-idle");
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+	
+	sleep(opt_log_interval);
+	pthread_testcancel();
+	run_cmd(cmd_idle);
+	
+	return NULL;
+}
+
 static struct work *hash_pop(void)
 {
 	struct work *work = NULL, *tmp;
 	int hc;
+	bool did_cmd_idle = false;
+	pthread_t cmd_idle_thr;
 
 retry:
 	mutex_lock(stgd_lock);
@@ -9323,14 +9339,16 @@ retry:
 			no_work = true;
 		}
 		pthread_cond_signal(&gws_cond);
-		const struct timeval tv = { .tv_sec = opt_log_interval, };
-		if (ETIMEDOUT == bfg_cond_timedwait(&getq->cond, stgd_lock, &tv))
+		
+		if (cmd_idle && !did_cmd_idle)
 		{
-			run_cmd(cmd_idle);
-			pthread_cond_signal(&gws_cond);
-			pthread_cond_wait(&getq->cond, stgd_lock);
+			if (likely(!pthread_create(&cmd_idle_thr, NULL, cmd_idle_thread, NULL)))
+				did_cmd_idle = true;
 		}
+		pthread_cond_wait(&getq->cond, stgd_lock);
 	}
+	if (did_cmd_idle)
+		pthread_cancel(cmd_idle_thr);
 	
 	no_work = false;
 

+ 1 - 51
util.c

@@ -1186,7 +1186,6 @@ void _now_is_not_set(__maybe_unused struct timeval *tv)
 void (*timer_set_now)(struct timeval *tv) = _now_is_not_set;
 void (*cgsleep_us_r)(cgtimer_t *, int64_t) = _cgsleep_us_r_nanosleep;
 
-static clockid_t bfg_timedwait_clk;
 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
 static clockid_t bfg_timer_clk;
 
@@ -1232,58 +1231,9 @@ bool _bfg_try_clock_gettime(clockid_t clk)
 }
 #endif
 
-int bfg_cond_timedwait(pthread_cond_t * restrict cond, pthread_mutex_t * restrict mutex, const struct timeval *tvp)
-{
-	struct timespec ts;
-	clock_gettime(bfg_timedwait_clk, &ts);
-	ts.tv_sec += tvp->tv_sec;
-	ts.tv_nsec += (long)tvp->tv_usec * 1000;
-	if (ts.tv_nsec > 1000000000L)
-	{
-		++ts.tv_sec;
-		ts.tv_nsec -= 1000000000L;
-	}
-	return pthread_cond_timedwait(cond, mutex, &ts);
-}
-
 pthread_condattr_t *bfg_condattr_()
 {
-	static pthread_condattr_t attr;
-	static bool initialized;
-	
-	if (unlikely(!initialized))
-	{
-		pthread_condattr_init(&attr);
-#ifdef HAVE_CLOCK_GETTIME_MONOTONIC
-#ifdef HAVE_CLOCK_GETTIME_MONOTONIC_RAW
-		if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC_RAW))
-		{
-			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_MONOTONIC_RAW");
-			bfg_timedwait_clk = CLOCK_MONOTONIC_RAW;
-		}
-		else
-#endif
-		if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
-		{
-			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_MONOTONIC");
-			bfg_timedwait_clk = CLOCK_MONOTONIC;
-		}
-		else
-#endif
-		if (!pthread_condattr_setclock(&attr, CLOCK_REALTIME))
-		{
-			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_REALTIME");
-			bfg_timedwait_clk = CLOCK_REALTIME;
-		}
-		else
-		{
-			applog(LOG_DEBUG, "Timers: Cannot find a clock for cond timedwait");
-			return NULL;
-		}
-		initialized = true;
-	}
-	
-	return &attr;
+	return NULL;
 }
 
 static