Browse Source

Use the curses_lock to protect the curses_active variable and test it under lock.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
a593afdbeb
  1. 117
      main.c
  2. 3
      miner.h
  3. 22
      util.c

117
main.c

@ -1391,6 +1391,27 @@ static char statusline[256];
static int cpucursor, gpucursor, logstart, logcursor; static int cpucursor, gpucursor, logstart, logcursor;
static struct cgpu_info *gpus, *cpus; static struct cgpu_info *gpus, *cpus;
static inline void unlock_curses(void)
{
mutex_unlock(&curses_lock);
}
static inline void lock_curses(void)
{
mutex_lock(&curses_lock);
}
static bool curses_active_locked(void)
{
bool ret;
lock_curses();
ret = curses_active;
if (!ret)
unlock_curses();
return ret;
}
static void text_print_status(int thr_id) static void text_print_status(int thr_id)
{ {
struct cgpu_info *cgpu = thr_info[thr_id].cgpu; struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
@ -1483,13 +1504,11 @@ static void curses_print_status(int thr_id)
static void print_status(int thr_id) static void print_status(int thr_id)
{ {
if (!curses_active) if (curses_active_locked()) {
text_print_status(thr_id);
else {
mutex_lock(&curses_lock);
curses_print_status(thr_id); curses_print_status(thr_id);
mutex_unlock(&curses_lock); unlock_curses();
} } else
text_print_status(thr_id);
} }
/* Check for window resize. Called with curses mutex locked */ /* Check for window resize. Called with curses mutex locked */
@ -1523,14 +1542,13 @@ static void wlogprint(const char *f, ...)
{ {
va_list ap; va_list ap;
mutex_lock(&curses_lock); if (curses_active_locked()) {
va_start(ap, f);
va_start(ap, f); vw_printw(logwin, f, ap);
vw_printw(logwin, f, ap); va_end(ap);
va_end(ap); wrefresh(logwin);
wrefresh(logwin); unlock_curses();
}
mutex_unlock(&curses_lock);
} }
void log_curses(int prio, const char *f, va_list ap) void log_curses(int prio, const char *f, va_list ap)
@ -1538,23 +1556,23 @@ void log_curses(int prio, const char *f, va_list ap)
if (opt_quiet && prio != LOG_ERR) if (opt_quiet && prio != LOG_ERR)
return; return;
if (curses_active) { if (curses_active_locked()) {
if (!opt_loginput) { if (!opt_loginput) {
mutex_lock(&curses_lock);
vw_printw(logwin, f, ap); vw_printw(logwin, f, ap);
wrefresh(logwin); wrefresh(logwin);
mutex_unlock(&curses_lock);
} }
unlock_curses();
} else } else
vprintf(f, ap); vprintf(f, ap);
} }
static void clear_logwin(void) static void clear_logwin(void)
{ {
mutex_lock(&curses_lock); if (curses_active_locked()) {
wclear(logwin); wclear(logwin);
wrefresh(logwin); wrefresh(logwin);
mutex_unlock(&curses_lock); unlock_curses();
}
} }
static bool submit_upstream_work(const struct work *work) static bool submit_upstream_work(const struct work *work)
@ -1765,7 +1783,8 @@ static void workio_cmd_free(struct workio_cmd *wc)
static void disable_curses(void) static void disable_curses(void)
{ {
if (test_and_clear(&curses_active)) { if (curses_active_locked()) {
curses_active = false;
leaveok(logwin, false); leaveok(logwin, false);
leaveok(statuswin, false); leaveok(statuswin, false);
leaveok(mainwin, false); leaveok(mainwin, false);
@ -1775,8 +1794,7 @@ static void disable_curses(void)
delwin(statuswin); delwin(statuswin);
delwin(mainwin); delwin(mainwin);
endwin(); endwin();
refresh(); refresh();
#ifdef WIN32 #ifdef WIN32
// Move the cursor to after curses output. // Move the cursor to after curses output.
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
@ -1789,6 +1807,7 @@ static void disable_curses(void)
SetConsoleCursorPosition(hout, coord); SetConsoleCursorPosition(hout, coord);
} }
#endif #endif
unlock_curses();
} }
} }
@ -2302,24 +2321,25 @@ static void display_pool_summary(struct pool *pool)
{ {
double efficiency = 0.0; double efficiency = 0.0;
mutex_lock(&curses_lock); if (curses_active_locked()) {
wlog("Pool: %s\n", pool->rpc_url); wlog("Pool: %s\n", pool->rpc_url);
wlog("%s long-poll support\n", pool->hdr_path ? "Has" : "Does not have"); wlog("%s long-poll support\n", pool->hdr_path ? "Has" : "Does not have");
wlog(" Queued work requests: %d\n", pool->getwork_requested); wlog(" Queued work requests: %d\n", pool->getwork_requested);
wlog(" Share submissions: %d\n", pool->accepted + pool->rejected); wlog(" Share submissions: %d\n", pool->accepted + pool->rejected);
wlog(" Accepted shares: %d\n", pool->accepted); wlog(" Accepted shares: %d\n", pool->accepted);
wlog(" Rejected shares: %d\n", pool->rejected); wlog(" Rejected shares: %d\n", pool->rejected);
if (pool->accepted || pool->rejected) if (pool->accepted || pool->rejected)
wlog(" Reject ratio: %.1f\n", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected)); wlog(" Reject ratio: %.1f\n", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected));
efficiency = pool->getwork_requested ? pool->accepted * 100.0 / pool->getwork_requested : 0.0; efficiency = pool->getwork_requested ? pool->accepted * 100.0 / pool->getwork_requested : 0.0;
wlog(" Efficiency (accepted / queued): %.0f%%\n", efficiency); wlog(" Efficiency (accepted / queued): %.0f%%\n", efficiency);
wlog(" Discarded work due to new blocks: %d\n", pool->discarded_work); wlog(" Discarded work due to new blocks: %d\n", pool->discarded_work);
wlog(" Stale submissions discarded due to new blocks: %d\n", pool->stale_shares); wlog(" Stale submissions discarded due to new blocks: %d\n", pool->stale_shares);
wlog(" Unable to get work from server occasions: %d\n", pool->localgen_occasions); wlog(" Unable to get work from server occasions: %d\n", pool->localgen_occasions);
wlog(" Submitting work remotely delay occasions: %d\n\n", pool->remotefail_occasions); wlog(" Submitting work remotely delay occasions: %d\n\n", pool->remotefail_occasions);
wrefresh(logwin); wrefresh(logwin);
mutex_unlock(&curses_lock); unlock_curses();
}
} }
/* We can't remove the memory used for this struct pool because there may /* We can't remove the memory used for this struct pool because there may
@ -4138,15 +4158,14 @@ static void *watchdog_thread(void *userdata)
hashmeter(-1, &zero_tv, 0); hashmeter(-1, &zero_tv, 0);
if (curses_active) { if (curses_active_locked()) {
mutex_lock(&curses_lock);
for (i = 0; i < mining_threads; i++) for (i = 0; i < mining_threads; i++)
curses_print_status(i); curses_print_status(i);
if (!change_logwinsize()) { if (!change_logwinsize()) {
redrawwin(statuswin); redrawwin(statuswin);
redrawwin(logwin); redrawwin(logwin);
} }
mutex_unlock(&curses_lock); unlock_curses();
} }
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
@ -4480,8 +4499,11 @@ out:
static void enable_curses(void) { static void enable_curses(void) {
int x,y; int x,y;
if (curses_active) lock_curses();
if (curses_active) {
unlock_curses();
return; return;
}
mainwin = initscr(); mainwin = initscr();
getmaxyx(mainwin, y, x); getmaxyx(mainwin, y, x);
@ -4493,7 +4515,8 @@ static void enable_curses(void) {
leaveok(logwin, true); leaveok(logwin, true);
cbreak(); cbreak();
noecho(); noecho();
test_and_set(&curses_active); curses_active = true;
unlock_curses();
} }
int main (int argc, char *argv[]) int main (int argc, char *argv[])

3
miner.h

@ -325,7 +325,6 @@ extern bool use_syslog;
extern struct thr_info *thr_info; extern struct thr_info *thr_info;
extern int longpoll_thr_id; extern int longpoll_thr_id;
extern struct work_restart *work_restart; extern struct work_restart *work_restart;
extern pthread_mutex_t control_lock;
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
typedef struct { typedef struct {
@ -423,8 +422,6 @@ extern bool tq_push(struct thread_q *tq, void *data);
extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime); extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
extern void tq_freeze(struct thread_q *tq); extern void tq_freeze(struct thread_q *tq);
extern void tq_thaw(struct thread_q *tq); extern void tq_thaw(struct thread_q *tq);
extern bool test_and_set(bool *var);
extern bool test_and_clear(bool *var);
extern bool successful_connect; extern bool successful_connect;
extern enum cl_kernel chosen_kernel; extern enum cl_kernel chosen_kernel;

22
util.c

@ -43,28 +43,6 @@
bool successful_connect = false; bool successful_connect = false;
bool test_and_set(bool *var)
{
bool ret;
mutex_lock(&control_lock);
ret = *var;
*var = true;
mutex_unlock(&control_lock);
return ret;
}
bool test_and_clear(bool *var)
{
bool ret;
mutex_lock(&control_lock);
ret = *var;
*var = false;
mutex_unlock(&control_lock);
return ret;
}
struct data_buffer { struct data_buffer {
void *buf; void *buf;
size_t len; size_t len;

Loading…
Cancel
Save