mirror of
https://github.com/GOSTSec/sgminer
synced 2025-03-09 20:21:01 +00:00
Deuglify use of _PARSE_COMMANDS macro expansions.
This commit is contained in:
parent
303a763162
commit
5e1ebd5070
27
api.c
27
api.c
@ -1211,6 +1211,9 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
|
||||
return root;
|
||||
}
|
||||
|
||||
#define DRIVER_COUNT_DRV(X) if (devices[i]->drv->drv_id == DRIVER_##X) \
|
||||
count++;
|
||||
|
||||
#ifdef HAVE_AN_ASIC
|
||||
static int numascs(void)
|
||||
{
|
||||
@ -1219,11 +1222,7 @@ static int numascs(void)
|
||||
|
||||
rd_lock(&devices_lock);
|
||||
for (i = 0; i < total_devices; i++) {
|
||||
#define DRIVER_ADD_COMMAND(X) \
|
||||
if (devices[i]->drv->drv_id == DRIVER_##X) \
|
||||
count++;
|
||||
ASIC_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
|
||||
}
|
||||
rd_unlock(&devices_lock);
|
||||
return count;
|
||||
@ -1236,11 +1235,7 @@ static int ascdevice(int ascid)
|
||||
|
||||
rd_lock(&devices_lock);
|
||||
for (i = 0; i < total_devices; i++) {
|
||||
#define DRIVER_ADD_COMMAND(X) \
|
||||
if (devices[i]->drv->drv_id == DRIVER_##X) \
|
||||
count++;
|
||||
ASIC_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
|
||||
if (count == (ascid + 1))
|
||||
goto foundit;
|
||||
}
|
||||
@ -1263,11 +1258,7 @@ static int numpgas(void)
|
||||
|
||||
rd_lock(&devices_lock);
|
||||
for (i = 0; i < total_devices; i++) {
|
||||
#define DRIVER_ADD_COMMAND(X) \
|
||||
if (devices[i]->drv->drv_id == DRIVER_##X) \
|
||||
count++;
|
||||
FPGA_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
|
||||
}
|
||||
rd_unlock(&devices_lock);
|
||||
return count;
|
||||
@ -1280,11 +1271,7 @@ static int pgadevice(int pgaid)
|
||||
|
||||
rd_lock(&devices_lock);
|
||||
for (i = 0; i < total_devices; i++) {
|
||||
#define DRIVER_ADD_COMMAND(X) \
|
||||
if (devices[i]->drv->drv_id == DRIVER_##X) \
|
||||
count++;
|
||||
FPGA_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
|
||||
if (count == (pgaid + 1))
|
||||
goto foundit;
|
||||
}
|
||||
|
17
cgminer.c
17
cgminer.c
@ -7604,6 +7604,8 @@ static void hotplug_process()
|
||||
switch_logsize(true);
|
||||
}
|
||||
|
||||
#define DRIVER_DRV_DETECT_HOTPLUG(X) X##_drv.drv_detect(true);
|
||||
|
||||
static void *hotplug_thread(void __maybe_unused *userdata)
|
||||
{
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
@ -7625,9 +7627,7 @@ static void *hotplug_thread(void __maybe_unused *userdata)
|
||||
|
||||
/* Use the DRIVER_PARSE_COMMANDS macro to detect all
|
||||
* devices */
|
||||
#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(true);
|
||||
DRIVER_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_HOTPLUG)
|
||||
|
||||
if (new_devices)
|
||||
hotplug_process();
|
||||
@ -7653,6 +7653,9 @@ static void probe_pools(void)
|
||||
}
|
||||
}
|
||||
|
||||
#define DRIVER_FILL_DEVICE_DRV(X) fill_device_drv(&X##_drv);
|
||||
#define DRIVER_DRV_DETECT_ALL(X) X##_drv.drv_detect(false);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sigaction handler;
|
||||
@ -7834,17 +7837,13 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
/* Use the DRIVER_PARSE_COMMANDS macro to fill all the device_drvs */
|
||||
#define DRIVER_ADD_COMMAND(X) fill_device_drv(&X##_drv);
|
||||
DRIVER_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_FILL_DEVICE_DRV)
|
||||
|
||||
if (opt_scrypt)
|
||||
opencl_drv.drv_detect(false);
|
||||
else {
|
||||
/* Use the DRIVER_PARSE_COMMANDS macro to detect all devices */
|
||||
#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(false);
|
||||
DRIVER_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_ALL)
|
||||
}
|
||||
|
||||
if (opt_display_devs) {
|
||||
|
21
miner.h
21
miner.h
@ -234,34 +234,33 @@ static inline int fsync (int fd)
|
||||
* trying to claim same chip but different devices. Adding a device here will
|
||||
* update all macros in the code that use the *_PARSE_COMMANDS macros for each
|
||||
* listed driver. */
|
||||
#define FPGA_PARSE_COMMANDS \
|
||||
#define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
|
||||
DRIVER_ADD_COMMAND(bitforce) \
|
||||
DRIVER_ADD_COMMAND(icarus) \
|
||||
DRIVER_ADD_COMMAND(modminer) \
|
||||
DRIVER_ADD_COMMAND(ztex)
|
||||
|
||||
#define ASIC_PARSE_COMMANDS \
|
||||
#define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
|
||||
DRIVER_ADD_COMMAND(bflsc) \
|
||||
DRIVER_ADD_COMMAND(bitfury) \
|
||||
DRIVER_ADD_COMMAND(avalon)
|
||||
|
||||
#define DRIVER_PARSE_COMMANDS \
|
||||
#define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
|
||||
DRIVER_ADD_COMMAND(opencl) \
|
||||
FPGA_PARSE_COMMANDS \
|
||||
ASIC_PARSE_COMMANDS
|
||||
FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
|
||||
ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
|
||||
|
||||
#define DRIVER_ENUM(X) DRIVER_##X,
|
||||
#define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
|
||||
|
||||
/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
|
||||
#define DRIVER_ADD_COMMAND(X) DRIVER_##X,
|
||||
enum drv_driver {
|
||||
DRIVER_PARSE_COMMANDS
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
|
||||
DRIVER_MAX
|
||||
};
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
|
||||
/* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
|
||||
#define DRIVER_ADD_COMMAND(X) struct device_drv X##_drv;
|
||||
DRIVER_PARSE_COMMANDS;
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
|
||||
|
||||
enum alive {
|
||||
LIFE_WELL,
|
||||
|
20
usbutils.c
20
usbutils.c
@ -1840,6 +1840,9 @@ static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *dr
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define DRIVER_USB_CHECK_EACH(X) if (drv->drv_id == DRIVER_##X) \
|
||||
return usb_check_each(DRIVER_##X, drv, dev);
|
||||
|
||||
static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv, __maybe_unused struct libusb_device *dev)
|
||||
{
|
||||
if (drv_count[drv->drv_id].count >= drv_count[drv->drv_id].limit) {
|
||||
@ -1849,11 +1852,7 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define DRIVER_ADD_COMMAND(X) \
|
||||
if (drv->drv_id == DRIVER_##X) \
|
||||
return usb_check_each(DRIVER_##X, drv, dev);
|
||||
DRIVER_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_USB_CHECK_EACH)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -3125,6 +3124,10 @@ void usb_cleanup()
|
||||
cgsem_destroy(&usb_resource_sem);
|
||||
}
|
||||
|
||||
#define DRIVER_COUNT_FOUND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
|
||||
drv_count[X##_drv.drv_id].limit = lim; \
|
||||
found = true; \
|
||||
}
|
||||
void usb_initialise()
|
||||
{
|
||||
char *fre, *ptr, *comma, *colon;
|
||||
@ -3210,12 +3213,7 @@ void usb_initialise()
|
||||
found = false;
|
||||
/* Use the DRIVER_PARSE_COMMANDS macro to iterate
|
||||
* over all the drivers. */
|
||||
#define DRIVER_ADD_COMMAND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
|
||||
drv_count[X##_drv.drv_id].limit = lim; \
|
||||
found = true; \
|
||||
}
|
||||
DRIVER_PARSE_COMMANDS
|
||||
#undef DRIVER_ADD_COMMAND
|
||||
DRIVER_PARSE_COMMANDS(DRIVER_COUNT_FOUND)
|
||||
if (!found)
|
||||
quit(1, "Invalid --usb DRV:limit - unknown DRV='%s'", ptr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user