Browse Source

Merge branch 'bugfix_cancel_mutex' into bfgminer

Luke Dashjr 13 years ago
parent
commit
b84119c8bc
3 changed files with 38 additions and 5 deletions
  1. 5 0
      logging.c
  2. 18 5
      miner.c
  3. 15 0
      miner.h

+ 5 - 0
logging.c

@@ -32,12 +32,17 @@ static void my_log_curses(__maybe_unused int prio, char *f, va_list ap)
 #endif
 #endif
 	{
 	{
 		int len = strlen(f);
 		int len = strlen(f);
+		int cancelstate;
+		bool scs;
 
 
 		strcpy(f + len - 1, "                    \n");
 		strcpy(f + len - 1, "                    \n");
 
 
+		scs = !pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate);
 		mutex_lock(&console_lock);
 		mutex_lock(&console_lock);
 		vprintf(f, ap);
 		vprintf(f, ap);
 		mutex_unlock(&console_lock);
 		mutex_unlock(&console_lock);
+		if (scs)
+			pthread_setcancelstate(cancelstate, &cancelstate);
 	}
 	}
 }
 }
 
 

+ 18 - 5
miner.c

@@ -1464,6 +1464,24 @@ static bool curses_active_locked(void)
 		unlock_curses();
 		unlock_curses();
 	return ret;
 	return ret;
 }
 }
+
+// Cancellable getch
+int my_cancellable_getch(void)
+{
+	// This only works because the macro only hits direct getch() calls
+	typedef int (*real_getch_t)(void);
+	const real_getch_t real_getch = __real_getch;
+
+	int type, rv;
+	bool sct;
+
+	sct = !pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &type);
+	rv = real_getch();
+	if (sct)
+		pthread_setcanceltype(type, &type);
+
+	return rv;
+}
 #endif
 #endif
 
 
 void tailsprintf(char *f, const char *fmt, ...)
 void tailsprintf(char *f, const char *fmt, ...)
@@ -3110,7 +3128,6 @@ static void *stage_thread(void *userdata)
 	bool ok = true;
 	bool ok = true;
 
 
 	rename_thr("bfg-stage");
 	rename_thr("bfg-stage");
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 
 	while (ok) {
 	while (ok) {
 		struct work *work = NULL;
 		struct work *work = NULL;
@@ -3783,7 +3800,6 @@ retry:
 static void *input_thread(void __maybe_unused *userdata)
 static void *input_thread(void __maybe_unused *userdata)
 {
 {
 	rename_thr("bfg-input");
 	rename_thr("bfg-input");
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 
 	if (!curses_active)
 	if (!curses_active)
 		return NULL;
 		return NULL;
@@ -3846,7 +3862,6 @@ static void *workio_thread(void *userdata)
 	bool ok = true;
 	bool ok = true;
 
 
 	rename_thr("bfg-workio");
 	rename_thr("bfg-workio");
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 
 	while (ok) {
 	while (ok) {
 		struct workio_cmd *wc;
 		struct workio_cmd *wc;
@@ -4999,7 +5014,6 @@ static void reap_curl(struct pool *pool)
 static void *watchpool_thread(void __maybe_unused *userdata)
 static void *watchpool_thread(void __maybe_unused *userdata)
 {
 {
 	rename_thr("bfg-watchpool");
 	rename_thr("bfg-watchpool");
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 
 	while (42) {
 	while (42) {
 		struct timeval now;
 		struct timeval now;
@@ -5066,7 +5080,6 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 	struct timeval zero_tv;
 	struct timeval zero_tv;
 
 
 	rename_thr("bfg-watchdog");
 	rename_thr("bfg-watchdog");
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 
 	memset(&zero_tv, 0, sizeof(struct timeval));
 	memset(&zero_tv, 0, sizeof(struct timeval));
 	gettimeofday(&rotate_tv, NULL);
 	gettimeofday(&rotate_tv, NULL);

+ 15 - 0
miner.h

@@ -175,6 +175,21 @@ void *alloca (size_t);
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 #endif
 
 
+#ifdef HAVE_CURSES
+#	ifdef getch
+		// getch() is a macro
+		static int __maybe_unused __real_getch(void) {
+			return getch();
+		}
+#		undef getch
+#		define getch()  my_cancellable_getch()
+#	else
+		// getch() is a real function
+#		define __real_getch  getch
+#		define getch()  my_cancellable_getch()
+#	endif
+#endif
+
 enum alive {
 enum alive {
 	LIFE_WELL,
 	LIFE_WELL,
 	LIFE_SICK,
 	LIFE_SICK,