Browse Source

Merge commit 'bd652a6' into cg_merges_20130524b

Conflicts:
	miner.c
Luke Dashjr 12 years ago
parent
commit
d31af0975a
2 changed files with 12 additions and 11 deletions
  1. 9 0
      deviceapi.c
  2. 3 11
      miner.c

+ 9 - 0
deviceapi.c

@@ -153,6 +153,10 @@ void minerloop_scanhash(struct thr_info *mythr)
 	struct work *work;
 	const bool primary = (!mythr->device_thread) || mythr->primary_thread;
 	
+#ifdef HAVE_PTHREAD_CANCEL
+	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
+#endif
+	
 	while (1) {
 		mythr->work_restart = false;
 		request_work(mythr);
@@ -163,9 +167,14 @@ void minerloop_scanhash(struct thr_info *mythr)
 		
 		do {
 			thread_reportin(mythr);
+			/* Only allow the mining thread to be cancelled when
+			* it is not in the driver code. */
+			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 			gettimeofday(&tv_start, NULL);
 			hashes = api->scanhash(mythr, work, work->blk.nonce + max_nonce);
 			gettimeofday(&tv_end, NULL);
+			pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+			pthread_testcancel();
 			thread_reportin(mythr);
 			
 			timersub(&tv_end, &tv_start, &tv_hashes);

+ 3 - 11
miner.c

@@ -3454,23 +3454,15 @@ static void __kill_work(void)
 	thr = &control_thr[watchdog_thr_id];
 	thr_info_cancel(thr);
 
-	applog(LOG_DEBUG, "Stopping mining threads");
-	/* Stop the mining threads*/
-	for (i = 0; i < mining_threads; i++) {
-		thr = get_thread(i);
-		if (thr->cgpu->threads)
-			thr_info_freeze(thr);
-		thr->pause = true;
-	}
-
-	nmsleep(1000);
-
 	applog(LOG_DEBUG, "Killing off mining threads");
 	/* Kill the mining threads*/
 	for (i = 0; i < mining_threads; i++) {
 		thr = get_thread(i);
 		if (thr->cgpu->threads)
+		{
 			thr_info_cancel(thr);
+			pthread_join(thr->pth, NULL);
+		}
 	}
 
 	applog(LOG_DEBUG, "Killing off stage thread");