Browse Source

minerloop_async: Break out of select on work_restart_notifier

Luke Dashjr 13 years ago
parent
commit
ad9f5df249
3 changed files with 23 additions and 1 deletions
  1. 10 1
      deviceapi.c
  2. 5 0
      miner.c
  3. 8 0
      util.h

+ 10 - 1
deviceapi.c

@@ -12,10 +12,13 @@
 
 
 #include "config.h"
 #include "config.h"
 
 
+#include <sys/select.h>
 #include <stdbool.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <sys/time.h>
 #include <sys/time.h>
+#include <sys/types.h>
 #include <time.h>
 #include <time.h>
+#include <unistd.h>
 
 
 #include "compat.h"
 #include "compat.h"
 #include "deviceapi.h"
 #include "deviceapi.h"
@@ -286,6 +289,9 @@ void minerloop_async(struct thr_info *mythr)
 	fd_set rfds;
 	fd_set rfds;
 	bool is_running, should_be_running;
 	bool is_running, should_be_running;
 	
 	
+	if (mythr->work_restart_notifier[1] == -1)
+		notifier_init(mythr->work_restart_notifier);
+	
 	while (1) {
 	while (1) {
 		tv_timeout.tv_sec = -1;
 		tv_timeout.tv_sec = -1;
 		gettimeofday(&tv_now, NULL);
 		gettimeofday(&tv_now, NULL);
@@ -330,15 +336,18 @@ djp: ;
 		}
 		}
 		
 		
 		gettimeofday(&tv_now, NULL);
 		gettimeofday(&tv_now, NULL);
-		// FIXME: break select on work restart
 		FD_ZERO(&rfds);
 		FD_ZERO(&rfds);
 		FD_SET(mythr->notifier[0], &rfds);
 		FD_SET(mythr->notifier[0], &rfds);
 		maxfd = mythr->notifier[0];
 		maxfd = mythr->notifier[0];
+		FD_SET(mythr->work_restart_notifier[0], &rfds);
+		set_maxfd(&maxfd, mythr->work_restart_notifier[0]);
 		if (select(maxfd + 1, &rfds, NULL, NULL, select_timeout(&tv_timeout, &tv_now)) < 0)
 		if (select(maxfd + 1, &rfds, NULL, NULL, select_timeout(&tv_timeout, &tv_now)) < 0)
 			continue;
 			continue;
 		if (FD_ISSET(mythr->notifier[0], &rfds)) {
 		if (FD_ISSET(mythr->notifier[0], &rfds)) {
 			notifier_read(mythr->notifier);
 			notifier_read(mythr->notifier);
 		}
 		}
+		if (FD_ISSET(mythr->work_restart_notifier[0], &rfds))
+			notifier_read(mythr->work_restart_notifier);
 	}
 	}
 }
 }
 
 

+ 5 - 0
miner.c

@@ -4334,6 +4334,11 @@ static void restart_threads(void)
 	{
 	{
 		thr = &thr_info[i];
 		thr = &thr_info[i];
 		thr->work_restart = true;
 		thr->work_restart = true;
+	}
+	
+	for (i = 0; i < mining_threads; i++)
+	{
+		thr = &thr_info[i];
 		notifier_wake(thr->work_restart_notifier);
 		notifier_wake(thr->work_restart_notifier);
 	}
 	}
 
 

+ 8 - 0
util.h

@@ -83,6 +83,14 @@ static inline void align_len(size_t *len)
 }
 }
 
 
 
 
+static inline
+void set_maxfd(int *p_maxfd, int fd)
+{
+	if (fd > *p_maxfd)
+		*p_maxfd = fd;
+}
+
+
 #define timer_set_delay(tvp_timer, tvp_now, usecs)  do {  \
 #define timer_set_delay(tvp_timer, tvp_now, usecs)  do {  \
 	struct timeval tv_add = {  \
 	struct timeval tv_add = {  \
 		.tv_sec = usecs / 1000000,  \
 		.tv_sec = usecs / 1000000,  \