Browse Source

Optimise new_share for the common case where shares are new, minimising time under wlock

master
Con Kolivas 10 years ago
parent
commit
f8e644e959
  1. 22
      src/stratifier.c

22
src/stratifier.c

@ -2652,24 +2652,26 @@ static double submission_diff(stratum_instance_t *client, workbase_t *wb, const
return ret; return ret;
} }
/* Optimised for the common case where shares are new */
static bool new_share(sdata_t *sdata, const uchar *hash, int64_t wb_id) static bool new_share(sdata_t *sdata, const uchar *hash, int64_t wb_id)
{ {
share_t *share, *match = NULL; share_t *share = ckzalloc(sizeof(share_t)), *match = NULL;
bool ret = false; bool ret = true;
ck_wlock(&sdata->share_lock);
HASH_FIND(hh, sdata->shares, hash, 32, match);
if (match)
goto out_unlock;
share = ckzalloc(sizeof(share_t));
memcpy(share->hash, hash, 32); memcpy(share->hash, hash, 32);
share->workbase_id = wb_id; share->workbase_id = wb_id;
ck_wlock(&sdata->share_lock);
sdata->shares_generated++; sdata->shares_generated++;
HASH_ADD(hh, sdata->shares, hash, 32, share); HASH_FIND(hh, sdata->shares, hash, 32, match);
ret = true; if (likely(!match))
out_unlock: HASH_ADD(hh, sdata->shares, hash, 32, share);
ck_wunlock(&sdata->share_lock); ck_wunlock(&sdata->share_lock);
if (unlikely(match)) {
dealloc(share);
ret = false;
}
return ret; return ret;
} }

Loading…
Cancel
Save