Browse Source

stale_work_future function to determine in advance if a work/share will be stale at some future time

Luke Dashjr 13 years ago
parent
commit
279be4e9c2
2 changed files with 21 additions and 10 deletions
  1. 20 10
      miner.c
  2. 1 0
      miner.h

+ 20 - 10
miner.c

@@ -4277,6 +4277,25 @@ int restart_wait(unsigned int mstime)
 	return rc;
 }
 
+bool stale_work_future(struct work *work, bool share, unsigned long ustime)
+{
+	bool rv;
+	struct timeval tv, orig;
+	ldiv_t d;
+	
+	d = ldiv(ustime, 1000000);
+	tv = (struct timeval){
+		.tv_sec = d.quot,
+		.tv_usec = d.rem,
+	};
+	orig = work->tv_staged;
+	timersub(&orig, &tv, &work->tv_staged);
+	rv = stale_work(work, share);
+	work->tv_staged = orig;
+	
+	return rv;
+}
+
 /* A generic wait function for threads that poll that will wait a specified
  * time waiting on a share to become stale. Returns positive if the share
  * became stale or zero if the timer expired first. If checkend is true, will
@@ -4289,16 +4308,7 @@ int stale_wait(unsigned int mstime, struct work*work, bool checkend)
 	int rc;
 
 	if (checkend) {
-		struct timeval tv, orig;
-		ldiv_t d;
-		d = ldiv(mstime, 1000);
-		tv.tv_sec = d.quot;
-		tv.tv_usec = d.rem * 1000;
-		orig = work->tv_staged;
-		timersub(&orig, &tv, &work->tv_staged);
-		rc = stale_work(work, true);
-		work->tv_staged = orig;
-		if (rc)
+		if (stale_work_future(work, true, mstime * 1000))
 			return -1;
 	}
 

+ 1 - 0
miner.h

@@ -791,6 +791,7 @@ extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportout(struct thr_info *);
 extern void hashmeter2(struct thr_info *);
 extern int restart_wait(unsigned int mstime);
+extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
 extern int stale_wait(unsigned int mstime, struct work*, bool checkend);
 
 extern void kill_work(void);