Browse Source

Move queueing of one request to separate function in preparation for variable length queues.

Con Kolivas 14 years ago
parent
commit
131f60a5ee
1 changed files with 19 additions and 17 deletions
  1. 19 17
      cpu-miner.c

+ 19 - 17
cpu-miner.c

@@ -693,19 +693,17 @@ static void hashmeter(int thr_id, struct timeval *diff,
 	local_mhashes_done = 0;
 	local_mhashes_done = 0;
 }
 }
 
 
-static bool get_work(struct work *work)
+/* All work is queued flagged as being for thread 0 and then the mining thread
+ * flags it as its own */
+static bool queue_request(void)
 {
 {
 	struct thr_info *thr = &thr_info[0];
 	struct thr_info *thr = &thr_info[0];
-	struct work *work_heap;
 	struct workio_cmd *wc;
 	struct workio_cmd *wc;
-	bool ret = false;
-	static bool first_work = true;
 
 
-get_new:
 	/* fill out work request message */
 	/* fill out work request message */
 	wc = calloc(1, sizeof(*wc));
 	wc = calloc(1, sizeof(*wc));
 	if (unlikely(!wc))
 	if (unlikely(!wc))
-		goto out;
+		return false;
 
 
 	wc->cmd = WC_GET_WORK;
 	wc->cmd = WC_GET_WORK;
 	wc->thr = thr;
 	wc->thr = thr;
@@ -713,8 +711,21 @@ get_new:
 	/* send work request to workio thread */
 	/* send work request to workio thread */
 	if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
 	if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
 		workio_cmd_free(wc);
 		workio_cmd_free(wc);
-		goto out;
+		return false;
 	}
 	}
+	return true;
+}
+
+static bool get_work(struct work *work)
+{
+	struct thr_info *thr = &thr_info[0];
+	struct work *work_heap;
+	bool ret = false;
+	static bool first_work = true;
+
+get_new:
+	if (unlikely(!queue_request()))
+		goto out;
 
 
 	/* wait for 1st response, or get cached response */
 	/* wait for 1st response, or get cached response */
 	work_heap = tq_pop(thr->q, NULL);
 	work_heap = tq_pop(thr->q, NULL);
@@ -733,17 +744,8 @@ get_new:
 		first_work = false;
 		first_work = false;
 		/* send for another work request for the next time get_work
 		/* send for another work request for the next time get_work
 		 * is called. */
 		 * is called. */
-		wc = calloc(1, sizeof(*wc));
-		if (unlikely(!wc))
-			goto out_free;
-
-		wc->cmd = WC_GET_WORK;
-		wc->thr = thr;
-
-		if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
-			workio_cmd_free(wc);
+		if (unlikely(!queue_request()))
 			goto out_free;
 			goto out_free;
-		}
 	}
 	}
 
 
 	memcpy(work, work_heap, sizeof(*work));
 	memcpy(work, work_heap, sizeof(*work));