mirror of
https://git.wownero.com/wownero/wownero-puddle.git
synced 2024-08-15 01:03:20 +00:00
use rwlock semantics for database resizing
This commit is contained in:
parent
c12b8b78e5
commit
047aef644c
1 changed files with 7 additions and 7 deletions
14
src/pool.c
14
src/pool.c
|
@ -275,7 +275,7 @@ static unsigned clients_reading;
|
||||||
static pthread_cond_t cond_clients = PTHREAD_COND_INITIALIZER;
|
static pthread_cond_t cond_clients = PTHREAD_COND_INITIALIZER;
|
||||||
static pthread_mutex_t mutex_clients = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mutex_clients = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_mutex_t mutex_log = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mutex_log = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_mutex_t mutex_tx = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_rwlock_t rwlock_tx = PTHREAD_RWLOCK_INITIALIZER;
|
||||||
static FILE *fd_log;
|
static FILE *fd_log;
|
||||||
static unsigned char sec_view[32];
|
static unsigned char sec_view[32];
|
||||||
static unsigned char pub_spend[32];
|
static unsigned char pub_spend[32];
|
||||||
|
@ -390,7 +390,7 @@ database_resize(void)
|
||||||
|
|
||||||
if(ei.me_mapsize < DB_INIT_SIZE)
|
if(ei.me_mapsize < DB_INIT_SIZE)
|
||||||
{
|
{
|
||||||
if ((rc = pthread_mutex_trylock(&mutex_tx)))
|
if ((rc = pthread_rwlock_trywrlock(&rwlock_tx)))
|
||||||
{
|
{
|
||||||
log_warn("Cannot cannot acquire lock");
|
log_warn("Cannot cannot acquire lock");
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -412,7 +412,7 @@ database_resize(void)
|
||||||
if ((double)used / ei.me_mapsize > threshold)
|
if ((double)used / ei.me_mapsize > threshold)
|
||||||
{
|
{
|
||||||
uint64_t ns = (uint64_t) ei.me_mapsize + DB_GROW_SIZE;
|
uint64_t ns = (uint64_t) ei.me_mapsize + DB_GROW_SIZE;
|
||||||
if ((rc = pthread_mutex_trylock(&mutex_tx)))
|
if ((rc = pthread_rwlock_trywrlock(&rwlock_tx)))
|
||||||
{
|
{
|
||||||
log_warn("Cannot cannot acquire lock");
|
log_warn("Cannot cannot acquire lock");
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -428,7 +428,7 @@ database_resize(void)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
unlock:
|
unlock:
|
||||||
pthread_mutex_unlock(&mutex_tx);
|
pthread_rwlock_unlock(&rwlock_tx);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,7 +636,7 @@ miner_balance(const char *address)
|
||||||
if (strlen(address) > ADDRESS_MAX)
|
if (strlen(address) > ADDRESS_MAX)
|
||||||
return balance;
|
return balance;
|
||||||
|
|
||||||
pthread_mutex_trylock(&mutex_tx);
|
pthread_rwlock_rdlock(&rwlock_tx);
|
||||||
|
|
||||||
if ((rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)) != 0)
|
if ((rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)) != 0)
|
||||||
{
|
{
|
||||||
|
@ -668,7 +668,7 @@ miner_balance(const char *address)
|
||||||
balance = *(uint64_t*)val.mv_data;
|
balance = *(uint64_t*)val.mv_data;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
pthread_mutex_unlock(&mutex_tx);
|
pthread_rwlock_unlock(&rwlock_tx);
|
||||||
if (cursor)
|
if (cursor)
|
||||||
mdb_cursor_close(cursor);
|
mdb_cursor_close(cursor);
|
||||||
if (txn)
|
if (txn)
|
||||||
|
@ -3984,7 +3984,7 @@ cleanup(void)
|
||||||
rx_slow_hash_free_state();
|
rx_slow_hash_free_state();
|
||||||
pthread_mutex_destroy(&mutex_clients);
|
pthread_mutex_destroy(&mutex_clients);
|
||||||
pthread_mutex_destroy(&mutex_log);
|
pthread_mutex_destroy(&mutex_log);
|
||||||
pthread_mutex_destroy(&mutex_tx);
|
pthread_rwlock_destroy(&rwlock_tx);
|
||||||
pthread_cond_destroy(&cond_clients);
|
pthread_cond_destroy(&cond_clients);
|
||||||
log_info("Pool shutdown successfully");
|
log_info("Pool shutdown successfully");
|
||||||
if (fd_log)
|
if (fd_log)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue