1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-09 14:28:12 +00:00

Do not double up with checking for end of timeout measurements in usb read/write.

This commit is contained in:
Con Kolivas 2013-11-05 13:55:06 +11:00
parent 8f6acad8ec
commit e692cd087f

View File

@ -2503,7 +2503,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
bool ftdi; bool ftdi;
struct timeval read_start, tv_finish; struct timeval read_start, tv_finish;
unsigned int initial_timeout; unsigned int initial_timeout;
double max, done;
int bufleft, err, got, tot, pstate; int bufleft, err, got, tot, pstate;
bool first = true; bool first = true;
bool dobuffer; bool dobuffer;
@ -2511,6 +2510,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
int endlen; int endlen;
unsigned char *ptr, *usbbuf = cgpu->usbinfo.bulkbuf; unsigned char *ptr, *usbbuf = cgpu->usbinfo.bulkbuf;
const size_t usbbufread = 512; /* Always read full size */ const size_t usbbufread = 512; /* Always read full size */
double done;
DEVRLOCK(cgpu, pstate); DEVRLOCK(cgpu, pstate);
@ -2544,7 +2544,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
err = LIBUSB_SUCCESS; err = LIBUSB_SUCCESS;
initial_timeout = timeout; initial_timeout = timeout;
max = ((double)timeout) / 1000.0;
cgtime(&read_start); cgtime(&read_start);
while (bufleft > 0) { while (bufleft > 0) {
got = 0; got = 0;
@ -2582,9 +2581,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
first = false; first = false;
done = tdiff(&tv_finish, &read_start); done = tdiff(&tv_finish, &read_start);
// N.B. this is: return LIBUSB_SUCCESS with whatever size has already been read // N.B. this is: return last err with whatever size has already been read
if (unlikely(done >= max))
break;
timeout = initial_timeout - (done * 1000); timeout = initial_timeout - (done * 1000);
if (timeout <= 0) if (timeout <= 0)
break; break;
@ -2616,7 +2613,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
endlen = strlen(end); endlen = strlen(end);
err = LIBUSB_SUCCESS; err = LIBUSB_SUCCESS;
initial_timeout = timeout; initial_timeout = timeout;
max = ((double)timeout) / 1000.0;
cgtime(&read_start); cgtime(&read_start);
while (bufleft > 0) { while (bufleft > 0) {
@ -2658,8 +2654,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
done = tdiff(&tv_finish, &read_start); done = tdiff(&tv_finish, &read_start);
// N.B. this is: return LIBUSB_SUCCESS with whatever size has already been read // N.B. this is: return LIBUSB_SUCCESS with whatever size has already been read
if (unlikely(done >= max))
break;
timeout = initial_timeout - (done * 1000); timeout = initial_timeout - (done * 1000);
if (timeout <= 0) if (timeout <= 0)
break; break;
@ -2719,11 +2713,11 @@ out_noerrmsg:
int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, enum usb_cmds cmd) int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, enum usb_cmds cmd)
{ {
struct cg_usb_device *usbdev; struct cg_usb_device *usbdev;
struct timeval read_start, tv_finish; struct timeval write_start, tv_finish;
unsigned int initial_timeout; unsigned int initial_timeout;
double max, done;
__maybe_unused bool first = true; __maybe_unused bool first = true;
int err, sent, tot, pstate; int err, sent, tot, pstate;
double done;
DEVRLOCK(cgpu, pstate); DEVRLOCK(cgpu, pstate);
@ -2745,8 +2739,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
tot = 0; tot = 0;
err = LIBUSB_SUCCESS; err = LIBUSB_SUCCESS;
initial_timeout = timeout; initial_timeout = timeout;
max = ((double)timeout) / 1000.0; cgtime(&write_start);
cgtime(&read_start);
while (bufsiz > 0) { while (bufsiz > 0) {
int tosend = bufsiz; int tosend = bufsiz;
@ -2775,10 +2768,8 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
first = false; first = false;
done = tdiff(&tv_finish, &read_start); done = tdiff(&tv_finish, &write_start);
// N.B. this is: return LIBUSB_SUCCESS with whatever size was written // N.B. this is: return last err with whatever size was written
if (unlikely(done >= max))
break;
timeout = initial_timeout - (done * 1000); timeout = initial_timeout - (done * 1000);
if (timeout <= 0) if (timeout <= 0)
break; break;