Browse Source

DevAPI: Modify add_cgpu to use temporary devices_new array, so detection can be done without touching live variables

Luke Dashjr 12 years ago
parent
commit
8be8a1fbe6
4 changed files with 12 additions and 4 deletions
  1. 3 3
      deviceapi.c
  2. 1 1
      driver-cpu.c
  3. 6 0
      miner.c
  4. 2 0
      miner.h

+ 3 - 3
deviceapi.c

@@ -608,8 +608,8 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	
-	devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + lpcount + 1));
-	devices[total_devices++] = cgpu;
+	devices_new = realloc(devices_new, sizeof(struct cgpu_info *) * (total_devices_new + lpcount + 1));
+	devices_new[total_devices_new++] = cgpu;
 	
 	if (lpcount > 1)
 	{
@@ -643,7 +643,7 @@ bool add_cgpu(struct cgpu_info *cgpu)
 				slave->proc_repr_ns[ns] += i;
 			}
 			slave->threads = tpp;
-			devices[total_devices++] = slave;
+			devices_new[total_devices_new++] = slave;
 			*nlp_p = slave;
 			nlp_p = &slave->next_proc;
 		}

+ 1 - 1
driver-cpu.c

@@ -745,7 +745,7 @@ static void cpu_detect()
 	#endif /* !WIN32 */
 
 	if (opt_n_threads < 0 || !forced_n_threads) {
-		if (total_devices && !opt_usecpu)
+		if ((total_devices || total_devices_new) && !opt_usecpu)
 			opt_n_threads = 0;
 		else
 			opt_n_threads = num_processors;

+ 6 - 0
miner.c

@@ -162,6 +162,8 @@ static bool opt_display_devs;
 static bool opt_removedisabled;
 int total_devices;
 struct cgpu_info **devices;
+int total_devices_new;
+struct cgpu_info **devices_new;
 bool have_opencl;
 int opt_n_threads = -1;
 int mining_threads;
@@ -8963,6 +8965,10 @@ int main(int argc, char *argv[])
 #endif
 
 	drv_detect_all();
+	total_devices = total_devices_new;
+	devices = devices_new;
+	total_devices_new = 0;
+	devices_new = NULL;
 
 	if (opt_display_devs) {
 		applog(LOG_ERR, "Devices detected:");

+ 2 - 0
miner.h

@@ -970,6 +970,8 @@ extern int mining_threads;
 extern struct cgpu_info *cpus;
 extern int total_devices;
 extern struct cgpu_info **devices;
+extern int total_devices_new;
+extern struct cgpu_info **devices_new;
 extern int total_pools;
 extern struct pool **pools;
 extern const char *algo_names[];