|
|
@@ -212,7 +212,7 @@ static int total_control_threads;
|
|
|
pthread_mutex_t hash_lock;
|
|
|
static pthread_mutex_t *stgd_lock;
|
|
|
pthread_mutex_t console_lock;
|
|
|
-pthread_mutex_t ch_lock;
|
|
|
+cglock_t ch_lock;
|
|
|
static pthread_rwlock_t blk_lock;
|
|
|
static pthread_mutex_t sshare_lock;
|
|
|
|
|
|
@@ -266,9 +266,12 @@ const
|
|
|
bool curses_active;
|
|
|
|
|
|
static char current_block[40];
|
|
|
+
|
|
|
+/* Protected by ch_lock */
|
|
|
static char *current_hash;
|
|
|
static uint32_t current_block_id;
|
|
|
char *current_fullhash;
|
|
|
+
|
|
|
static char datestamp[40];
|
|
|
static char blocktime[32];
|
|
|
struct timeval block_timeval;
|
|
|
@@ -1860,12 +1863,12 @@ void have_block_height(uint32_t block_id, uint32_t blkheight)
|
|
|
if (known_blkheight == blkheight)
|
|
|
return;
|
|
|
applog(LOG_DEBUG, "Learned that block id %08" PRIx32 " is height %" PRIu32, be32toh(block_id), blkheight);
|
|
|
- mutex_lock(&ch_lock);
|
|
|
+ cg_wlock(&ch_lock);
|
|
|
known_blkheight = blkheight;
|
|
|
known_blkheight_blkid = block_id;
|
|
|
if (block_id == current_block_id)
|
|
|
__update_block_title(NULL);
|
|
|
- mutex_unlock(&ch_lock);
|
|
|
+ cg_wunlock(&ch_lock);
|
|
|
}
|
|
|
|
|
|
static bool work_decode(struct pool *pool, struct work *work, json_t *val)
|
|
|
@@ -2486,8 +2489,10 @@ static void curses_print_status(void)
|
|
|
pool->sockaddr_url, pool->diff, have_longpoll ? "": "out", pool->rpc_user);
|
|
|
}
|
|
|
wclrtoeol(statuswin);
|
|
|
+ cg_rlock(&ch_lock);
|
|
|
mvwprintw(statuswin, 5, 0, " Block: %s Diff:%s (%s) Started: %s",
|
|
|
current_hash, block_diff, net_hashrate, blocktime);
|
|
|
+ cg_runlock(&ch_lock);
|
|
|
mvwhline(statuswin, 6, 0, '-', 80);
|
|
|
mvwhline(statuswin, statusy - 1, 0, '-', 80);
|
|
|
mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit",
|
|
|
@@ -4600,26 +4605,20 @@ static char *blkhashstr(unsigned char *hash)
|
|
|
static void set_curblock(char *hexstr, unsigned char *hash)
|
|
|
{
|
|
|
unsigned char hash_swap[32];
|
|
|
- char *old_hash;
|
|
|
|
|
|
current_block_id = ((uint32_t*)hash)[0];
|
|
|
strcpy(current_block, hexstr);
|
|
|
swap256(hash_swap, hash);
|
|
|
swap32tole(hash_swap, hash_swap, 32 / 4);
|
|
|
|
|
|
- /* Don't free current_hash directly to avoid dereferencing when read
|
|
|
- * elsewhere - and update block_timeval inside the same lock */
|
|
|
- mutex_lock(&ch_lock);
|
|
|
+ cg_wlock(&ch_lock);
|
|
|
gettimeofday(&block_timeval, NULL);
|
|
|
__update_block_title(hash_swap);
|
|
|
- old_hash = current_fullhash;
|
|
|
+ free(current_fullhash);
|
|
|
current_fullhash = bin2hex(hash_swap, 32);
|
|
|
- free(old_hash);
|
|
|
- mutex_unlock(&ch_lock);
|
|
|
-
|
|
|
get_timestamp(blocktime, &block_timeval);
|
|
|
-
|
|
|
applog(LOG_INFO, "New block: %s diff %s (%s)", current_hash, block_diff, net_hashrate);
|
|
|
+ cg_wunlock(&ch_lock);
|
|
|
}
|
|
|
|
|
|
/* Search to see if this string is from a block that has been seen before */
|
|
|
@@ -8287,7 +8286,7 @@ int main(int argc, char *argv[])
|
|
|
cglock_init(&control_lock);
|
|
|
mutex_init(&stats_lock);
|
|
|
mutex_init(&sharelog_lock);
|
|
|
- mutex_init(&ch_lock);
|
|
|
+ cglock_init(&ch_lock);
|
|
|
mutex_init(&sshare_lock);
|
|
|
rwlock_init(&blk_lock);
|
|
|
rwlock_init(&netacc_lock);
|