Roll as much work as possible from the work returned from a longpoll.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/cgminer.c b/cgminer.c
index a379034..264048d 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2089,6 +2089,18 @@ static void *stage_thread(void *userdata)
return NULL;
}
+static bool stage_work(struct work *work)
+{
+ if (opt_debug)
+ applog(LOG_DEBUG, "Pushing work to stage thread");
+
+ if (unlikely(!tq_push(thr_info[stage_thr_id].q, work))) {
+ applog(LOG_ERR, "Could not tq_push work in stage_work");
+ return false;
+ }
+ return true;
+}
+
int curses_int(const char *query)
{
int ret;
@@ -3055,7 +3067,7 @@ retry:
if (opt_debug)
applog(LOG_DEBUG, "Pushing divided work to get queue head");
- hash_push(work_heap);
+ stage_work(work_heap);
work->clone = true;
} else {
dec_queued();
@@ -3320,7 +3332,7 @@ enum {
/* Stage another work item from the work returned in a longpoll */
static void convert_to_work(json_t *val, bool rolltime, struct pool *pool)
{
- struct work *work;
+ struct work *work, *work_clone;
bool rc;
work = make_work();
@@ -3338,11 +3350,24 @@ static void convert_to_work(json_t *val, bool rolltime, struct pool *pool)
* allows testwork to know whether LP discovered the block or not. */
test_work_current(work, true);
+ work_clone = make_work();
+ memcpy(work_clone, work, sizeof(struct work));
+ while (reuse_work(work)) {
+ work_clone->clone = true;
+ if (opt_debug)
+ applog(LOG_DEBUG, "Pushing rolled converted work to stage thread");
+ if (unlikely(!stage_work(work_clone)))
+ break;
+ work_clone = make_work();
+ memcpy(work_clone, work, sizeof(struct work));
+ }
+ free_work(work_clone);
+
if (opt_debug)
applog(LOG_DEBUG, "Pushing converted work to stage thread");
- if (unlikely(!tq_push(thr_info[stage_thr_id].q, work)))
- applog(LOG_ERR, "Could not tq_push work in convert_to_work");
+ if (unlikely(!stage_work(work)))
+ free_work(work);
else if (opt_debug)
applog(LOG_DEBUG, "Converted longpoll data to work");
}