From f7fc0ce859efa7a95f1b26a7e83b7d8320be9589 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 2 Apr 2017 05:19:12 +1000 Subject: [PATCH] Readd removed workbases to the remote workbase list outside of the HASH_ITER loop we originally removed them from in check_incomplete_wbs. --- src/stratifier.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index e359deed..3e2f95a3 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1737,14 +1737,15 @@ static void __add_to_remote_workbases(sdata_t *sdata, workbase_t *wb) static void check_incomplete_wbs(ckpool_t *ckp, sdata_t *sdata) { - workbase_t *wb, *tmp; + workbase_t *wb, *tmp, *removed = NULL; int incomplete = 0; ck_wlock(&sdata->workbase_lock); HASH_ITER(hh, sdata->remote_workbases, wb, tmp) { if (!wb->incomplete || wb->readcount) continue; - /* Remove the workbase from the hashlist so we can work on it */ + /* Remove the workbase from the hashlist so we can work on it + * without holding the lock */ HASH_DEL(sdata->remote_workbases, wb); ck_wunlock(&sdata->workbase_lock); @@ -1753,8 +1754,15 @@ static void check_incomplete_wbs(ckpool_t *ckp, sdata_t *sdata) else incomplete++; - /* Readd it to the hashlist */ + /* Add it to a list of removed workbases, to be returned once + * we exit this HASH_ITER loop. */ + HASH_ADD(hh, removed, id, sizeof(int64_t) * 2, wb); + ck_wlock(&sdata->workbase_lock); + } + /* Return all removed workbases to remote_workbase hashlist */ + HASH_ITER(hh, removed, wb, tmp) { + HASH_DEL(removed, wb); __add_to_remote_workbases(sdata, wb); } ck_wunlock(&sdata->workbase_lock);