1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 20:44:19 +00:00

call a separate get_devices() with locking, as required

This commit is contained in:
Kano 2013-02-08 02:12:09 +11:00
parent 1c69417def
commit bc5755233c
5 changed files with 39 additions and 57 deletions

49
api.c
View File

@ -1194,13 +1194,17 @@ static int pgadevice(int pgaid)
if (devices[i]->drv->drv_id == DRIVER_MODMINER) if (devices[i]->drv->drv_id == DRIVER_MODMINER)
count++; count++;
#endif #endif
if (count == (pgaid + 1)) { if (count == (pgaid + 1))
mutex_unlock(&devices_lock); goto foundit;
return i;
}
} }
mutex_unlock(&devices_lock); mutex_unlock(&devices_lock);
return -1; return -1;
foundit:
mutex_unlock(&devices_lock);
return i;
} }
#endif #endif
@ -1533,14 +1537,9 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
if (dev < 0) // Should never happen if (dev < 0) // Should never happen
return; return;
struct cgpu_info *cgpu; struct cgpu_info *cgpu = get_devices(dev);
double frequency = 0; double frequency = 0;
float temp; float temp = cgpu->temp;
mutex_lock(&devices_lock);
cgpu = devices[dev];
mutex_unlock(&devices_lock);
temp = cgpu->temp;
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (cgpu->drv->drv_id == DRIVER_ZTEX && cgpu->device_ztex) if (cgpu->drv->drv_id == DRIVER_ZTEX && cgpu->device_ztex)
@ -1787,9 +1786,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
return; return;
} }
mutex_lock(&devices_lock); cgpu = get_devices(dev);
cgpu = devices[dev];
mutex_unlock(&devices_lock);
applog(LOG_DEBUG, "API: request to pgaenable pgaid %d device %d %s%u", applog(LOG_DEBUG, "API: request to pgaenable pgaid %d device %d %s%u",
id, dev, cgpu->drv->name, cgpu->device_id); id, dev, cgpu->drv->name, cgpu->device_id);
@ -1854,9 +1851,7 @@ static void pgadisable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
return; return;
} }
mutex_lock(&devices_lock); cgpu = get_devices(dev);
cgpu = devices[dev];
mutex_unlock(&devices_lock);
applog(LOG_DEBUG, "API: request to pgadisable pgaid %d device %d %s%u", applog(LOG_DEBUG, "API: request to pgadisable pgaid %d device %d %s%u",
id, dev, cgpu->drv->name, cgpu->device_id); id, dev, cgpu->drv->name, cgpu->device_id);
@ -1900,9 +1895,7 @@ static void pgaidentify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, ch
return; return;
} }
mutex_lock(&devices_lock); cgpu = get_devices(dev);
cgpu = devices[dev];
mutex_unlock(&devices_lock);
drv = cgpu->drv; drv = cgpu->drv;
if (!drv->identify_device) if (!drv->identify_device)
@ -2830,9 +2823,7 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
io_open = io_add(io_data, COMSTR JSON_NOTIFY); io_open = io_add(io_data, COMSTR JSON_NOTIFY);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
mutex_lock(&devices_lock); cgpu = get_devices(i);
cgpu = devices[i];
mutex_unlock(&devices_lock);
notifystatus(io_data, i, cgpu, isjson, group); notifystatus(io_data, i, cgpu, isjson, group);
} }
@ -2859,9 +2850,7 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
io_open = io_add(io_data, COMSTR JSON_DEVDETAILS); io_open = io_add(io_data, COMSTR JSON_DEVDETAILS);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
mutex_lock(&devices_lock); cgpu = get_devices(i);
cgpu = devices[i];
mutex_unlock(&devices_lock);
root = api_add_int(root, "DEVDETAILS", &i, false); root = api_add_int(root, "DEVDETAILS", &i, false);
root = api_add_string(root, "Name", cgpu->drv->name, false); root = api_add_string(root, "Name", cgpu->drv->name, false);
@ -2971,9 +2960,7 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
i = 0; i = 0;
for (j = 0; j < total_devices; j++) { for (j = 0; j < total_devices; j++) {
mutex_lock(&devices_lock); cgpu = get_devices(j);
cgpu = devices[j];
mutex_unlock(&devices_lock);
if (cgpu && cgpu->drv) { if (cgpu && cgpu->drv) {
if (cgpu->drv->get_api_stats) if (cgpu->drv->get_api_stats)
@ -3248,9 +3235,7 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
return; return;
} }
mutex_lock(&devices_lock); cgpu = get_devices(dev);
cgpu = devices[dev];
mutex_unlock(&devices_lock);
drv = cgpu->drv; drv = cgpu->drv;
char *set = strchr(opt, ','); char *set = strchr(opt, ',');

View File

@ -390,6 +390,16 @@ static struct cgpu_info *get_thr_cgpu(int thr_id)
return thr->cgpu; 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) static void sharelog(const char*disposition, const struct work*work)
{ {
char *target, *hash, *data; char *target, *hash, *data;
@ -4043,11 +4053,7 @@ void zero_stats(void)
zero_bestshare(); zero_bestshare();
for (i = 0; i < total_devices; ++i) { for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu; struct cgpu_info *cgpu = get_devices(i);
mutex_lock(&devices_lock);
cgpu = devices[i];
mutex_unlock(&devices_lock);
mutex_lock(&hash_lock); mutex_lock(&hash_lock);
cgpu->total_mhashes = 0; cgpu->total_mhashes = 0;
@ -5967,17 +5973,12 @@ static void *watchdog_thread(void __maybe_unused *userdata)
} }
for (i = 0; i < total_devices; ++i) { for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu; struct cgpu_info *cgpu = get_devices(i);
struct thr_info *thr; struct thr_info *thr = cgpu->thr[0];
enum dev_enable *denable; enum dev_enable *denable;
char dev_str[8]; char dev_str[8];
int gpu; int gpu;
mutex_lock(&devices_lock);
cgpu = devices[i];
mutex_unlock(&devices_lock);
thr = cgpu->thr[0];
if (cgpu->drv->get_stats) if (cgpu->drv->get_stats)
cgpu->drv->get_stats(cgpu); cgpu->drv->get_stats(cgpu);
@ -6141,10 +6142,8 @@ void print_summary(void)
applog(LOG_WARNING, "Summary of per device statistics:\n"); applog(LOG_WARNING, "Summary of per device statistics:\n");
for (i = 0; i < total_devices; ++i) { for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu; struct cgpu_info *cgpu = get_devices(i);
mutex_lock(&devices_lock);
cgpu = devices[i];
mutex_unlock(&devices_lock);
log_print_status(cgpu); log_print_status(cgpu);
} }

View File

@ -389,10 +389,11 @@ static void ztex_shutdown(struct thr_info *thr)
static void ztex_disable(struct thr_info *thr) static void ztex_disable(struct thr_info *thr)
{ {
struct cgpu_info *cgpu;
applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr); applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr);
mutex_lock(&devices_lock); cgpu = get_devices(thr->cgpu->device_id);
devices[thr->cgpu->device_id]->deven = DEV_DISABLED; cgpu->deven = DEV_DISABLED;
mutex_unlock(&devices_lock);
ztex_shutdown(thr); ztex_shutdown(thr);
} }

View File

@ -1110,6 +1110,7 @@ extern void free_work(struct work *work);
extern void __copy_work(struct work *work, struct work *base_work); extern void __copy_work(struct work *work, struct work *base_work);
extern struct work *copy_work(struct work *base_work); extern struct work *copy_work(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);
enum api_data_type { enum api_data_type {
API_ESCAPE, API_ESCAPE,

View File

@ -624,9 +624,7 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint
case WAIT_ABANDONED: case WAIT_ABANDONED:
// Am I using it already? // Am I using it already?
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
mutex_lock(&devices_lock); cgpu = get_devices(i);
cgpu = devices[i];
mutex_unlock(&devices_lock);
if (cgpu->usbinfo.bus_number == bus_number && if (cgpu->usbinfo.bus_number == bus_number &&
cgpu->usbinfo.device_address == device_address && cgpu->usbinfo.device_address == device_address &&
cgpu->usbinfo.nodev == false) { cgpu->usbinfo.nodev == false) {
@ -867,9 +865,7 @@ static void release_cgpu(struct cgpu_info *cgpu)
// Any devices sharing the same USB device should be marked also // Any devices sharing the same USB device should be marked also
// Currently only MMQ shares a USB device // Currently only MMQ shares a USB device
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
mutex_lock(&devices_lock); lookcgpu = get_devices(i);
lookcgpu = devices[i];
mutex_unlock(&devices_lock);
if (lookcgpu != cgpu && lookcgpu->usbdev == cgusb) { if (lookcgpu != cgpu && lookcgpu->usbdev == cgusb) {
lookcgpu->usbinfo.nodev = true; lookcgpu->usbinfo.nodev = true;
lookcgpu->usbinfo.nodev_count++; lookcgpu->usbinfo.nodev_count++;