Simplify submit_nonce loop and avoid potentially missing FOUND - 1 entry. Reported by Luke-Jr.
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84
diff --git a/findnonce.c b/findnonce.c
index a5da20a..35fd14e 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -161,29 +161,13 @@ struct pc_data {
pthread_t pth;
};
-static void *postcalc_hash(void *userdata)
+static void send_nonce(struct pc_data *pcd, cl_uint nonce)
{
- struct pc_data *pcd = (struct pc_data *)userdata;
- struct thr_info *thr = pcd->thr;
dev_blk_ctx *blk = &pcd->work->blk;
- struct work *work = pcd->work;
-
+ struct thr_info *thr = pcd->thr;
cl_uint A, B, C, D, E, F, G, H;
+ struct work *work = pcd->work;
cl_uint W[16];
- cl_uint nonce = 0;
- int entry = 0;
-
- pthread_detach(pthread_self());
-cycle:
- while (entry < FOUND) {
- if (pcd->res[entry]) {
- nonce = pcd->res[entry++];
- break;
- }
- entry++;
- }
- if (entry == FOUND)
- goto out;
A = blk->cty_a; B = blk->cty_b;
C = blk->cty_c; D = blk->cty_d;
@@ -215,20 +199,40 @@ cycle:
FR(48); PFR(56);
if (likely(H == 0xA41F32E7)) {
- if (unlikely(submit_nonce(thr, work, nonce) == false)) {
+ if (unlikely(submit_nonce(thr, work, nonce) == false))
applog(LOG_ERR, "Failed to submit work, exiting");
- goto out;
- }
} else {
if (opt_debug)
applog(LOG_DEBUG, "No best_g found! Error in OpenCL code?");
hw_errors++;
thr->cgpu->hw_errors++;
}
- if (entry < FOUND)
- goto cycle;
-out:
+}
+
+static void *postcalc_hash(void *userdata)
+{
+ struct pc_data *pcd = (struct pc_data *)userdata;
+ struct thr_info *thr = pcd->thr;
+ int entry = 0, nonces = 0;
+
+ pthread_detach(pthread_self());
+
+ do {
+ if (pcd->res[entry]) {
+ send_nonce(pcd, pcd->res[entry]);
+ nonces++;
+ }
+ } while (++entry < FOUND);
+
free(pcd);
+
+ if (unlikely(!nonces)) {
+ if (opt_debug)
+ applog(LOG_DEBUG, "No nonces found! Error in OpenCL code?");
+ hw_errors++;
+ thr->cgpu->hw_errors++;
+ }
+
return NULL;
}