Browse Source

Merge commit 'c91a954' into bfgminer

Luke Dashjr 13 years ago
parent
commit
694ab3dfeb
1 changed files with 22 additions and 3 deletions
  1. 22 3
      miner.c

+ 22 - 3
miner.c

@@ -2456,14 +2456,29 @@ static int global_queued(void)
 	return ret;
 }
 
+static bool enough_work(void)
+{
+	int cq, cs, ts, tq, maxq = opt_queue + mining_threads;
+
+	cq = current_queued();
+	cs = current_staged();
+	ts = total_staged();
+	tq = global_queued();
+
+	if (((cs || cq >= opt_queue) && ts >= maxq) ||
+	    ((cs || cq) && tq >= maxq))
+		return true;
+	return false;
+}
+
 /* ce and pool may appear uninitialised at push_curl_entry, but they're always
  * set when we don't have opt_benchmark enabled */
 static void *get_work_thread(void *userdata)
 {
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
-	struct curl_ent * uninitialised_var(ce);
 	struct pool * uninitialised_var(pool);
-	struct work *ret_work = make_work();
+	struct curl_ent *ce = NULL;
+	struct work *ret_work;
 	int failures = 0;
 
 	pthread_detach(pthread_self());
@@ -2471,6 +2486,10 @@ static void *get_work_thread(void *userdata)
 
 	applog(LOG_DEBUG, "Creating extra get work thread");
 
+	if (enough_work())
+		goto out;
+
+	ret_work = make_work();
 	if (wc->thr)
 		ret_work->thr = wc->thr;
 	else
@@ -2515,7 +2534,7 @@ static void *get_work_thread(void *userdata)
 
 out:
 	workio_cmd_free(wc);
-	if (!opt_benchmark)
+	if (ce)
 		push_curl_entry(ce, pool);
 	return NULL;
 }