Browse Source

Follow strict time_t handling rules

Luke Dashjr 13 years ago
parent
commit
18e0e8bdd4
1 changed files with 9 additions and 9 deletions
  1. 9 9
      miner.c

+ 9 - 9
miner.c

@@ -3497,11 +3497,10 @@ static bool workio_get_work(struct workio_cmd *wc)
 
 
 static bool stale_work(struct work *work, bool share)
 static bool stale_work(struct work *work, bool share)
 {
 {
-	struct timeval now;
-	time_t work_expiry;
+	unsigned work_expiry;
 	struct pool *pool;
 	struct pool *pool;
 	uint32_t block_id;
 	uint32_t block_id;
-	int getwork_delay;
+	unsigned getwork_delay;
 
 
 	block_id = ((uint32_t*)work->data)[1];
 	block_id = ((uint32_t*)work->data)[1];
 	pool = work->pool;
 	pool = work->pool;
@@ -3514,7 +3513,7 @@ static bool stale_work(struct work *work, bool share)
 	else
 	else
 		work_expiry = opt_expiry;
 		work_expiry = opt_expiry;
 
 
-	int max_expiry = (have_longpoll ? opt_expiry_lp : opt_expiry);
+	unsigned max_expiry = (have_longpoll ? opt_expiry_lp : opt_expiry);
 	if (work_expiry > max_expiry)
 	if (work_expiry > max_expiry)
 		work_expiry = max_expiry;
 		work_expiry = max_expiry;
 
 
@@ -3560,15 +3559,16 @@ static bool stale_work(struct work *work, bool share)
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	 * the nearest second */
 	 * the nearest second */
 	getwork_delay = pool->cgminer_pool_stats.getwork_wait_rolling * 5 + 1;
 	getwork_delay = pool->cgminer_pool_stats.getwork_wait_rolling * 5 + 1;
-	work_expiry -= getwork_delay;
-	if (unlikely(work_expiry < 5))
+	if (unlikely(work_expiry <= getwork_delay + 5))
 		work_expiry = 5;
 		work_expiry = 5;
+	else
+		work_expiry -= getwork_delay;
 
 
 	}
 	}
 
 
-	gettimeofday(&now, NULL);
-	if ((now.tv_sec - work->tv_staged.tv_sec) >= work_expiry) {
-		applog(LOG_DEBUG, "%s stale due to expiry (%d - %d >= %d)", share?"Share":"Work", now.tv_sec, work->tv_staged.tv_sec, work_expiry);
+	double elapsed_since_staged = difftime(time(NULL), work->tv_staged.tv_sec);
+	if (elapsed_since_staged > work_expiry) {
+		applog(LOG_DEBUG, "%s stale due to expiry (%.0f >= %u)", share?"Share":"Work", elapsed_since_staged, work_expiry);
 		return true;
 		return true;
 	}
 	}