Browse Source

improve locking to prevent race condition

stratum could respond faster than we are able to add the sent share into the hash, which could cause memory leaks
djm34
Jan Berdajs 11 years ago
parent
commit
19fcb5eae7
  1. 11
      sgminer.c

11
sgminer.c

@ -5450,9 +5450,13 @@ static void *stratum_sthread(void *userdata) @@ -5450,9 +5450,13 @@ static void *stratum_sthread(void *userdata)
while (time(NULL) < sshare->sshare_time + 120) {
bool sessionid_match;
mutex_lock(&sshare_lock);
if (likely(stratum_send(pool, s, strlen(s)))) {
int ssdiff;
if (pool_tclear(pool, &pool->submit_fail))
applog(LOG_WARNING, "%s communication resumed, submitting work", get_pool_name(pool));
sshare->sshare_sent = time(NULL);
ssdiff = sshare->sshare_sent - sshare->sshare_time;
if (opt_debug || ssdiff > 0) {
@ -5460,18 +5464,17 @@ static void *stratum_sthread(void *userdata) @@ -5460,18 +5464,17 @@ static void *stratum_sthread(void *userdata)
pool->pool_no, ssdiff);
}
mutex_lock(&sshare_lock);
HASH_ADD_INT(stratum_shares, id, sshare);
pool->sshares++;
mutex_unlock(&sshare_lock);
if (pool_tclear(pool, &pool->submit_fail))
applog(LOG_WARNING, "%s communication resumed, submitting work", get_pool_name(pool));
applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db");
submitted = true;
break;
}
else {
mutex_unlock(&sshare_lock);
}
if (!pool_tset(pool, &pool->submit_fail) && cnx_needed(pool)) {
applog(LOG_WARNING, "%s stratum share submission failure", get_pool_name(pool));
total_ro++;

Loading…
Cancel
Save