Commit 35cb7fd101aa29fab7cd99befc30d0d949c9a9ba

Con Kolivas 2012-08-20T11:16:38

Don't pause after failed getwork, set lagging flag and reassess.

diff --git a/cgminer.c b/cgminer.c
index a844576..2fa1f96 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2380,13 +2380,15 @@ static void *get_work_thread(void *userdata)
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
 	int ts, tq, maxq = opt_queue + mining_threads;
 	struct pool *pool = current_pool();
+	struct work *ret_work= NULL;
 	struct curl_ent *ce = NULL;
-	struct work *ret_work;
+	bool lagging = false;
 
 	pthread_detach(pthread_self());
 
 	applog(LOG_DEBUG, "Creating extra get work thread");
 
+retry:
 	tq = global_queued();
 	ts = total_staged();
 
@@ -2399,30 +2401,33 @@ static void *get_work_thread(void *userdata)
 	if (clone_available())
 		goto out;
 
-	ret_work = make_work();
+	if (!ret_work)
+		ret_work = make_work();
 	if (wc->thr)
 		ret_work->thr = wc->thr;
 	else
 		ret_work->thr = NULL;
 
-	if (opt_benchmark)
+	if (opt_benchmark) {
 		get_benchmark_work(ret_work);
-	else {
-		bool lagging = false;
+		ret_work->queued = true;
+	} else {
 
 		if (ts <= opt_queue)
 			lagging = true;
 		pool = ret_work->pool = select_pool(lagging);
 		inc_queued();
-		
-		ce = pop_curl_entry(pool);
+
+		if (!ce)
+			ce = pop_curl_entry(pool);
 
 		/* obtain new work from bitcoin via JSON-RPC */
-		while (!get_upstream_work(ret_work, ce->curl)) {
+		if (!get_upstream_work(ret_work, ce->curl)) {
 			/* pause, then restart work-request loop */
-			applog(LOG_DEBUG, "json_rpc_call failed on get work, retry after %d seconds",
-				opt_fail_pause);
-			sleep(opt_fail_pause);
+			applog(LOG_DEBUG, "json_rpc_call failed on get work, retrying");
+			lagging = true;
+			dec_queued();
+			goto retry;
 		}
 
 		ret_work->queued = true;
@@ -2438,6 +2443,8 @@ static void *get_work_thread(void *userdata)
 	}
 
 out:
+	if (ret_work && !ret_work->queued)
+		free_work(ret_work);
 	workio_cmd_free(wc);
 	if (ce)
 		push_curl_entry(ce, pool);