Browse Source

Bugfix: ztex: Only destroy libztex device after the last handle to it has been released

Luke Dashjr 12 years ago
parent
commit
138b437178
2 changed files with 7 additions and 2 deletions
  1. 6 2
      driver-ztex.c
  2. 1 0
      libztex.h

+ 6 - 2
driver-ztex.c

@@ -96,6 +96,7 @@ static int ztex_autodetect(void)
 		ztex_master = ztex_devices[i]->dev;
 		ztex_master->root = ztex_master;
 		fpgacount = libztex_numberOfFpgas(ztex_master);
+		ztex_master->handles = fpgacount;
 		ztex = ztex_setup(ztex_master, fpgacount);
 
 		totaldevs += fpgacount;
@@ -395,9 +396,12 @@ static void ztex_shutdown(struct thr_info *thr)
 		return;
 	
 	cgpu->device_ztex = NULL;
-	if (ztex->root->numberOfFpgas > 1 /*&& ztex->fpgaNum == 0*/)
-		pthread_mutex_destroy(&ztex->mutex);
 	applog(LOG_DEBUG, "%"PRIpreprv": shutdown", cgpu->proc_repr);
+	if (--ztex->handles)
+		return;
+	applog(LOG_DEBUG, "%s: No handles remaining, destroying libztex device", cgpu->dev_repr);
+	if (ztex->root->numberOfFpgas > 1)
+		pthread_mutex_destroy(&ztex->mutex);
 	libztex_destroy_device(ztex);
 }
 

+ 1 - 0
libztex.h

@@ -66,6 +66,7 @@ struct libztex_device {
 	struct dclk_data dclk;
 
 	int16_t numberOfFpgas;
+	int handles;
 	int selectedFpga;
 	bool parallelConfigSupport;