1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-03-13 06:01:03 +00:00

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
This commit is contained in:
Jan Berdajs 2014-07-11 19:02:44 +02:00
parent 283e8fbd1a
commit 19fcb5eae7

View File

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