Browse Source

Convert the ch_lock to cg_lock.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
fd87825bf9
  1. 4
      api.c
  2. 24
      cgminer.c
  3. 2
      miner.h

4
api.c

@ -3197,7 +3197,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may @@ -3197,7 +3197,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
#endif
root = api_add_const(root, "Hash Method", SHA256STR, false);
mutex_lock(&ch_lock);
cg_rlock(&ch_lock);
if (current_fullhash && *current_fullhash) {
root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
root = api_add_string(root, "Current Block Hash", current_fullhash, true);
@ -3206,7 +3206,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may @@ -3206,7 +3206,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
root = api_add_timeval(root, "Current Block Time", &t, true);
root = api_add_const(root, "Current Block Hash", BLANK, false);
}
mutex_unlock(&ch_lock);
cg_runlock(&ch_lock);
root = api_add_bool(root, "LP", &have_longpoll, false);
root = api_add_diff(root, "Network Difficulty", &current_diff, true);

24
cgminer.c

@ -176,7 +176,7 @@ pthread_mutex_t cgusb_lock; @@ -176,7 +176,7 @@ pthread_mutex_t cgusb_lock;
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;
@ -225,8 +225,11 @@ const @@ -225,8 +225,11 @@ const
bool curses_active;
static char current_block[40];
/* Protected by ch_lock */
static char *current_hash;
char *current_fullhash;
static char datestamp[40];
static char blocktime[32];
struct timeval block_timeval;
@ -1998,8 +2001,10 @@ static void curses_print_status(void) @@ -1998,8 +2001,10 @@ static void curses_print_status(void)
pool->has_gbt ? "GBT" : "LP", pool->rpc_user);
}
wclrtoeol(statuswin);
cg_rlock(&ch_lock);
mvwprintw(statuswin, 5, 0, " Block: %s... Diff:%s Started: %s Best share: %s ",
current_hash, block_diff, blocktime, best_share);
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",
@ -3555,27 +3560,20 @@ static void set_curblock(char *hexstr, unsigned char *hash) @@ -3555,27 +3560,20 @@ static void set_curblock(char *hexstr, unsigned char *hash)
{
unsigned char hash_swap[32];
unsigned char block_hash_swap[32];
char *old_hash;
strcpy(current_block, hexstr);
swap256(hash_swap, hash);
swap256(block_hash_swap, hash + 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);
old_hash = current_hash;
free(current_hash);
current_hash = bin2hex(hash_swap + 2, 8);
free(old_hash);
old_hash = current_fullhash;
free(current_fullhash);
current_fullhash = bin2hex(block_hash_swap, 32);
free(old_hash);
mutex_unlock(&ch_lock);
get_timestamp(blocktime, &block_timeval);
applog(LOG_INFO, "New block: %s... diff %s", current_hash, block_diff);
cg_wunlock(&ch_lock);
}
/* Search to see if this string is from a block that has been seen before */
@ -7038,7 +7036,7 @@ int main(int argc, char *argv[]) @@ -7038,7 +7036,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);

2
miner.h

@ -796,7 +796,7 @@ extern pthread_mutex_t cgusb_lock; @@ -796,7 +796,7 @@ extern pthread_mutex_t cgusb_lock;
extern cglock_t control_lock;
extern pthread_mutex_t hash_lock;
extern pthread_mutex_t console_lock;
extern pthread_mutex_t ch_lock;
extern cglock_t ch_lock;
extern pthread_rwlock_t mining_thr_lock;
extern pthread_rwlock_t devices_lock;

Loading…
Cancel
Save