Browse Source

rename get_proc_by_id() to get_devices()

Cherrypicked from bc5755233c1b1ecd22f9b7237dbd528462382f56

Conflicts:
	api.c
	driver-ztex.c
	miner.c
	usbutils.c
Kano 13 years ago
parent
commit
d143c27846
3 changed files with 40 additions and 38 deletions
  1. 21 14
      api.c
  2. 18 12
      miner.c
  3. 1 12
      miner.h

+ 21 - 14
api.c

@@ -1204,13 +1204,17 @@ static int pgadevice(int pgaid)
 			continue;
 #endif
 		++count;
-		if (count == (pgaid + 1)) {
-			mutex_unlock(&devices_lock);
-			return i;
-		}
+		if (count == (pgaid + 1))
+			goto foundit;
 	}
+
 	mutex_unlock(&devices_lock);
 	return -1;
+
+foundit:
+
+	mutex_unlock(&devices_lock);
+	return i;
 }
 #endif
 
@@ -1573,7 +1577,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
         int dev = pgadevice(pga);
         if (dev < 0) // Should never happen
                 return;
-        devstatus_an(io_data, get_proc_by_id(dev), isjson, precom);
+        devstatus_an(io_data, get_devices(dev), isjson, precom);
 }
 #endif
 
@@ -1603,7 +1607,7 @@ devinfo_internal(void (*func)(struct io_data *, struct cgpu_info*, bool, bool),
 		io_open = io_add(io_data, COMSTR JSON_DEVS);
 
 	for (i = 0; i < total_devices; ++i) {
-		func(io_data, get_proc_by_id(i), isjson, isjson && i > 0);
+		func(io_data, get_devices(i), isjson, isjson && i > 0);
 	}
 
 	if (isjson && io_open)
@@ -1716,7 +1720,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 		return;
 	}
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 
 	applog(LOG_DEBUG, "API: request to pgaenable pgaid %d device %d %s",
 			id, dev, cgpu->proc_repr_ns);
@@ -1766,7 +1770,7 @@ static void pgadisable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
 		return;
 	}
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 
 	applog(LOG_DEBUG, "API: request to pgadisable pgaid %d device %d %s",
 			id, dev, cgpu->proc_repr_ns);
@@ -1810,7 +1814,7 @@ static void pgaidentify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, ch
 		return;
 	}
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 	api = cgpu->api;
 
 	if (api->identify_device && api->identify_device(cgpu))
@@ -2666,6 +2670,7 @@ void notifystatus(struct io_data *io_data, int device, struct cgpu_info *cgpu, b
 
 static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, char group)
 {
+	struct cgpu_info *cgpu;
 	bool io_open = false;
 	int i;
 
@@ -2679,8 +2684,10 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
 	if (isjson)
 		io_open = io_add(io_data, COMSTR JSON_NOTIFY);
 
-	for (i = 0; i < total_devices; i++)
-		notifystatus(io_data, i, get_proc_by_id(i), isjson, group);
+	for (i = 0; i < total_devices; i++) {
+		cgpu = get_devices(i);
+		notifystatus(io_data, i, cgpu, isjson, group);
+	}
 
 	if (isjson && io_open)
 		io_close(io_data);
@@ -2705,7 +2712,7 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 		io_open = io_add(io_data, COMSTR JSON_DEVDETAILS);
 
 	for (i = 0; i < total_devices; i++) {
-		cgpu = get_proc_by_id(i);
+		cgpu = get_devices(i);
 
 		root = api_add_int(root, "DEVDETAILS", &i, false);
 		root = api_add_device_identifier(root, cgpu);
@@ -2814,7 +2821,7 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 
 	i = 0;
 	for (j = 0; j < total_devices; j++) {
-		cgpu = get_proc_by_id(j);
+		cgpu = get_devices(j);
 
 		if (cgpu && cgpu->api) {
 			if (cgpu->api->get_api_stats)
@@ -3056,7 +3063,7 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
 		return;
 	}
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 	api = cgpu->api;
 
 	char *set = strchr(opt, ',');

+ 18 - 12
miner.c

@@ -428,6 +428,16 @@ static struct cgpu_info *get_thr_cgpu(int thr_id)
 	return thr->cgpu;
 }
 
+struct cgpu_info *get_devices(int id)
+{
+	struct cgpu_info *cgpu;
+
+	mutex_lock(&devices_lock);
+	cgpu = devices[id];
+	mutex_unlock(&devices_lock);
+	return cgpu;
+}
+
 static void sharelog(const char*disposition, const struct work*work)
 {
 	char *target, *hash, *data;
@@ -1007,7 +1017,7 @@ static void load_temp_config()
 	target_n = temp_target_str;
 
 	for (i = 0; i < total_devices; ++i) {
-		cgpu = get_proc_by_id(i);
+		cgpu = get_devices(i);
 		
 		// cutoff default may be specified by driver during probe; otherwise, opt_cutofftemp (const)
 		if (!cgpu->cutofftemp)
@@ -5175,7 +5185,7 @@ void zero_stats(void)
 	zero_bestshare();
 
 	for (i = 0; i < total_devices; ++i) {
-		struct cgpu_info *cgpu = get_proc_by_id(i);
+		struct cgpu_info *cgpu = get_devices(i);
 
 		mutex_lock(&hash_lock);
 		cgpu->total_mhashes = 0;
@@ -7376,7 +7386,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			
 			for (i = 0; i < total_devices; ++i)
 			{
-				struct cgpu_info *cgpu = get_proc_by_id(i);
+				struct cgpu_info *cgpu = get_devices(i);
 				
 				/* Don't touch disabled devices */
 				if (cgpu->deven == DEV_DISABLED)
@@ -7386,15 +7396,12 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 		}
 
 		for (i = 0; i < total_devices; ++i) {
-			struct cgpu_info *cgpu;
-			struct thr_info *thr;
+			struct cgpu_info *cgpu = get_devices(i);
+			struct thr_info *thr = cgpu->thr[0];
 			enum dev_enable *denable;
 			char *dev_str = cgpu->proc_repr;
 			int gpu;
 
-			cgpu = get_proc_by_id(i);
-			thr = cgpu->thr[0];
-			
 			if (cgpu->api->get_stats)
 			  cgpu->api->get_stats(cgpu);
 
@@ -7597,10 +7604,9 @@ void print_summary(void)
 	}
 
 	applog(LOG_WARNING, "Summary of per device statistics:\n");
-	for (i = 0; i < total_devices; ++i)
-	{
-		struct cgpu_info *cgpu;
-		cgpu = get_proc_by_id(i);
+	for (i = 0; i < total_devices; ++i) {
+		struct cgpu_info *cgpu = get_devices(i);
+
 		if ((!cgpu->proc_id) && cgpu->next_proc)
 		{
 			// Device summary line

+ 1 - 12
miner.h

@@ -1169,18 +1169,7 @@ extern void free_work(struct work *work);
 extern void __copy_work(struct work *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);
-
-static inline
-struct cgpu_info *get_proc_by_id(int i)
-{
-	struct cgpu_info *proc;
-
-	mutex_lock(&devices_lock);
-	proc = devices[i];
-	mutex_unlock(&devices_lock);
-	return proc;
-}
-
+extern struct cgpu_info *get_devices(int id);
 
 enum api_data_type {
 	API_ESCAPE,