Don't waste the work we retrieve 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
diff --git a/main.c b/main.c
index 1b129fc..ed463a6 100644
--- a/main.c
+++ b/main.c
@@ -1802,6 +1802,30 @@ static void restart_threads(bool longpoll)
work_restart[i].restart = 1;
}
+/* Stage another work item from the work returned in a longpoll */
+static void convert_to_work(json_t *val)
+{
+ struct work *work;
+ bool rc;
+
+ work = calloc(sizeof(*work), 1);
+ if (unlikely(!work)) {
+ applog(LOG_ERR, "OOM in convert_to_work");
+ return;
+ }
+
+ rc= work_decode(json_object_get(val, "result"), work);
+ if (unlikely(!rc)) {
+ applog(LOG_ERR, "Could not convert longpoll data to work");
+ return;
+ }
+
+ if (unlikely(!tq_push(thr_info[stage_thr_id].q, work)))
+ applog(LOG_ERR, "Could not tq_push work in convert_to_work");
+ else if (opt_debug)
+ applog(LOG_DEBUG, "Converted longpoll data to work");
+}
+
static void *longpoll_thread(void *userdata)
{
struct thr_info *mythr = userdata;
@@ -1851,6 +1875,7 @@ static void *longpoll_thread(void *userdata)
val = json_rpc_call(curl, lp_url, rpc_userpass, rpc_req,
false, true);
if (likely(val)) {
+ convert_to_work(val);
failures = 0;
json_decref(val);