Browse Source

Merge branch 'stderr_lock' into bfgminer

Luke Dashjr 12 years ago
parent
commit
02c0dbe886
3 changed files with 48 additions and 41 deletions
  1. 19 22
      logging.c
  2. 8 18
      miner.c
  3. 21 1
      miner.h

+ 19 - 22
logging.c

@@ -25,27 +25,15 @@ bool opt_log_microseconds;
 /* per default priorities higher than LOG_NOTICE are logged */
 int opt_log_level = LOG_NOTICE;
 
-static void my_log_curses(int prio, const char *datetime, const char *str)
+static void _my_log_curses(int prio, const char *datetime, const char *str)
 {
-	if (opt_quiet && prio != LOG_ERR)
-		return;
-
 #ifdef HAVE_CURSES
 	extern bool use_curses;
-	if (use_curses && log_curses_only(prio, datetime, str))
+	if (use_curses && _log_curses_only(prio, datetime, str))
 		;
 	else
 #endif
-	{
-		int cancelstate;
-		bool scs;
-		scs = !pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate);
-		mutex_lock(&console_lock);
 		printf(" %s %s%s", datetime, str, "                    \n");
-		mutex_unlock(&console_lock);
-		if (scs)
-			pthread_setcancelstate(cancelstate, &cancelstate);
-	}
 }
 
 /* high-level logging function, based on global opt_log_level */
@@ -63,7 +51,9 @@ void _applog(int prio, const char *str)
 	if (0) {}
 #endif
 	else {
-		bool writetocon = opt_debug_console || (opt_log_output && prio != LOG_DEBUG) || prio <= LOG_NOTICE;
+		bool writetocon =
+			(opt_debug_console || (opt_log_output && prio != LOG_DEBUG) || prio <= LOG_NOTICE)
+		 && !(opt_quiet && prio != LOG_ERR);
 		bool writetofile = !isatty(fileno((FILE *)stderr));
 		if (!(writetocon || writetofile))
 			return;
@@ -91,13 +81,20 @@ void _applog(int prio, const char *str)
 		else
 			get_now_datestamp(datetime);
 
-		/* Only output to stderr if it's not going to the screen as well */
-		if (writetofile) {
-			fprintf(stderr, " %s %s\n", datetime, str);	/* atomic write to stderr */
-			fflush(stderr);
-		}
+		if (writetofile || writetocon)
+		{
+			bfg_console_lock();
+			
+			/* Only output to stderr if it's not going to the screen as well */
+			if (writetofile) {
+				fprintf(stderr, " %s %s\n", datetime, str);	/* atomic write to stderr */
+				fflush(stderr);
+			}
 
-		if (writetocon)
-			my_log_curses(prio, datetime, str);
+			if (writetocon)
+				_my_log_curses(prio, datetime, str);
+			
+			bfg_console_unlock();
+		}
 	}
 }

+ 8 - 18
miner.c

@@ -2199,22 +2199,12 @@ struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
 #endif
 struct cgpu_info *cpus;
 
-#ifdef HAVE_CURSES
-static bool _curses_cancel_disabled;
-static int _curses_prev_cancelstate;
+bool _bfg_console_cancel_disabled;
+int _bfg_console_prev_cancelstate;
 
-static inline void unlock_curses(void)
-{
-	mutex_unlock(&console_lock);
-	if (_curses_cancel_disabled)
-		pthread_setcancelstate(_curses_prev_cancelstate, &_curses_prev_cancelstate);
-}
-
-static inline void lock_curses(void)
-{
-	_curses_cancel_disabled = !pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &_curses_prev_cancelstate);
-	mutex_lock(&console_lock);
-}
+#ifdef HAVE_CURSES
+#define   lock_curses()  bfg_console_lock()
+#define unlock_curses()  bfg_console_unlock()
 
 static bool curses_active_locked(void)
 {
@@ -2848,13 +2838,14 @@ void _wlogprint(const char *str)
 #endif
 
 #ifdef HAVE_CURSES
-bool log_curses_only(int prio, const char *datetime, const char *str)
+bool _log_curses_only(int prio, const char *datetime, const char *str)
 {
 	bool high_prio;
 
 	high_prio = (prio == LOG_WARNING || prio == LOG_ERR);
 
-	if (curses_active_locked()) {
+	if (curses_active)
+	{
 		if (!opt_loginput || high_prio) {
 			wprintw(logwin, " %s %s\n", datetime, str);
 			if (high_prio) {
@@ -2862,7 +2853,6 @@ bool log_curses_only(int prio, const char *datetime, const char *str)
 				wrefresh(logwin);
 			}
 		}
-		unlock_curses();
 		return true;
 	}
 	return false;

+ 21 - 1
miner.h

@@ -905,6 +905,26 @@ extern cglock_t ch_lock;
 extern pthread_rwlock_t mining_thr_lock;
 extern pthread_rwlock_t devices_lock;
 
+
+extern bool _bfg_console_cancel_disabled;
+extern int _bfg_console_prev_cancelstate;
+
+static inline
+void bfg_console_lock(void)
+{
+	_bfg_console_cancel_disabled = !pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &_bfg_console_prev_cancelstate);
+	mutex_lock(&console_lock);
+}
+
+static inline
+void bfg_console_unlock(void)
+{
+	mutex_unlock(&console_lock);
+	if (_bfg_console_cancel_disabled)
+		pthread_setcancelstate(_bfg_console_prev_cancelstate, &_bfg_console_prev_cancelstate);
+}
+
+
 extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportout(struct thr_info *);
 extern void clear_stratum_shares(struct pool *pool);
@@ -1288,7 +1308,7 @@ extern void write_config(FILE *fcfg);
 extern void zero_bestshare(void);
 extern void zero_stats(void);
 extern void default_save_file(char *filename);
-extern bool log_curses_only(int prio, const char *datetime, const char *str);
+extern bool _log_curses_only(int prio, const char *datetime, const char *str);
 extern void clear_logwin(void);
 extern void logwin_update(void);
 extern bool pool_tclear(struct pool *pool, bool *var);