Browse Source

Split up scan_serial function to enable internally adding ad-hoc cgpu

Luke Dashjr 12 years ago
parent
commit
2541247739
4 changed files with 42 additions and 22 deletions
  1. 5 0
      deviceapi.c
  2. 2 0
      deviceapi.h
  3. 34 22
      miner.c
  4. 1 0
      miner.h

+ 5 - 0
deviceapi.c

@@ -672,6 +672,11 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	return true;
 	return true;
 }
 }
 
 
+void add_cgpu_live(void *p)
+{
+	add_cgpu(p);
+}
+
 int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
 int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
 {
 {
 	struct string_elist *iter, *tmp;
 	struct string_elist *iter, *tmp;

+ 2 - 0
deviceapi.h

@@ -32,6 +32,8 @@ extern void minerloop_queue(struct thr_info *);
 
 
 extern void *miner_thread(void *);
 extern void *miner_thread(void *);
 
 
+extern void add_cgpu_live(void*);
+
 typedef bool(*detectone_func_t)(const char*);
 typedef bool(*detectone_func_t)(const char*);
 typedef int(*autoscan_func_t)();
 typedef int(*autoscan_func_t)();
 
 

+ 34 - 22
miner.c

@@ -9402,21 +9402,12 @@ void start_cgpu(struct cgpu_info *cgpu)
 		proc_enable(cgpu);
 		proc_enable(cgpu);
 }
 }
 
 
-int scan_serial(const char *s)
+static
+void _scan_serial(void *p)
 {
 {
-	static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-	struct string_elist *orig_scan_devices;
-	int devcount, i, mining_threads_new = 0;
-	unsigned int k;
+	const char *s = p;
 	struct string_elist *iter, *tmp;
 	struct string_elist *iter, *tmp;
-	struct cgpu_info *cgpu;
-	struct thr_info *thr;
-	void *p;
-	char *dummy = "\0";
-	
-	mutex_lock(&mutex);
-	orig_scan_devices = scan_devices;
-	devcount = total_devices;
+	struct string_elist *orig_scan_devices = scan_devices;
 	
 	
 	if (s)
 	if (s)
 	{
 	{
@@ -9428,6 +9419,31 @@ int scan_serial(const char *s)
 	
 	
 	drv_detect_all();
 	drv_detect_all();
 	
 	
+	if (s)
+	{
+		DL_FOREACH_SAFE(scan_devices, iter, tmp)
+		{
+			string_elist_del(&scan_devices, iter);
+		}
+		scan_devices = orig_scan_devices;
+	}
+}
+
+int create_new_cgpus(void (*addfunc)(void*), void *arg)
+{
+	static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+	int devcount, i, mining_threads_new = 0;
+	unsigned int k;
+	struct cgpu_info *cgpu;
+	struct thr_info *thr;
+	void *p;
+	char *dummy = "\0";
+	
+	mutex_lock(&mutex);
+	devcount = total_devices;
+	
+	addfunc(arg);
+	
 	wr_lock(&devices_lock);
 	wr_lock(&devices_lock);
 	p = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + total_devices_new + 1));
 	p = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + total_devices_new + 1));
 	if (unlikely(!p))
 	if (unlikely(!p))
@@ -9483,15 +9499,6 @@ int scan_serial(const char *s)
 #endif
 #endif
 	
 	
 out:
 out:
-	if (s)
-	{
-		DL_FOREACH_SAFE(scan_devices, iter, tmp)
-		{
-			string_elist_del(&scan_devices, iter);
-		}
-		scan_devices = orig_scan_devices;
-	}
-	
 	total_devices_new = 0;
 	total_devices_new = 0;
 	
 	
 	devcount = total_devices - devcount;
 	devcount = total_devices - devcount;
@@ -9500,6 +9507,11 @@ out:
 	return devcount;
 	return devcount;
 }
 }
 
 
+int scan_serial(const char *s)
+{
+	return create_new_cgpus(_scan_serial, (void*)s);
+}
+
 static void probe_pools(void)
 static void probe_pools(void)
 {
 {
 	int i;
 	int i;

+ 1 - 0
miner.h

@@ -1329,6 +1329,7 @@ extern void __copy_work(struct work *work, const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
 extern struct thr_info *get_thread(int thr_id);
 extern struct thr_info *get_thread(int thr_id);
 extern struct cgpu_info *get_devices(int id);
 extern struct cgpu_info *get_devices(int id);
+extern int create_new_cgpus(void (*addfunc)(void*), void *arg);
 extern int scan_serial(const char *);
 extern int scan_serial(const char *);
 
 
 enum api_data_type {
 enum api_data_type {