Increment total_work under control lock.
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 69 70
diff --git a/cgminer.c b/cgminer.c
index 60816b6..a4784e0 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1835,6 +1835,18 @@ static void calc_midstate(struct work *work)
endian_flip32(work->midstate, work->midstate);
}
+/* Returns the current value of total_work and increments it */
+static int total_work_inc(void)
+{
+ int ret;
+
+ cg_wlock(&control_lock);
+ ret = total_work++;
+ cg_wunlock(&control_lock);
+
+ return ret;
+}
+
static struct work *make_work(void)
{
struct work *work = calloc(1, sizeof(struct work));
@@ -1842,9 +1854,7 @@ static struct work *make_work(void)
if (unlikely(!work))
quit(1, "Failed to calloc work in make_work");
- cg_wlock(&control_lock);
- work->id = total_work++;
- cg_wunlock(&control_lock);
+ work->id = total_work_inc();
return work;
}
@@ -1991,7 +2001,7 @@ static void gen_gbt_work(struct pool *pool, struct work *work)
local_work++;
work->pool = pool;
work->gbt = true;
- work->id = total_work++;
+ work->id = total_work_inc();
work->longpoll = false;
work->getwork_mode = GETWORK_MODE_GBT;
work->work_block = work_block;
@@ -3978,7 +3988,7 @@ void roll_work(struct work *work)
/* This is now a different work item so it needs a different ID for the
* hashtable */
- work->id = total_work++;
+ work->id = total_work_inc();
}
static void *submit_work_thread(void *userdata)
@@ -6885,7 +6895,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
work->pool = pool;
work->stratum = true;
work->nonce = 0;
- work->id = total_work++;
+ work->id = total_work_inc();
work->longpoll = false;
work->getwork_mode = GETWORK_MODE_STRATUM;
work->work_block = work_block;
@@ -7025,7 +7035,7 @@ static void gen_solo_work(struct pool *pool, struct work *work)
work->gbt = true;
work->pool = pool;
work->nonce = 0;
- work->id = total_work++;
+ work->id = total_work_inc();
work->longpoll = false;
work->getwork_mode = GETWORK_MODE_SOLO;
work->work_block = work_block;