Re: [PATCH v3] Staging: comedi: convert while loop to timeout in ni_mio_common.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 14, 2014 at 03:31:01PM -0600, Chase Southwood wrote:
> This patch to ni_mio_common.c changes a simple while loop to a timeout,
> which is preferred.
> 
> Signed-off-by: Chase Southwood <chase.southwood@xxxxxxxxx>
> ---
> 
> I removed the extra counter variable this time.  Greg, you mentioned that I could just look at the time that has expired to far, and exit and error out if that exceeds a limit.  Right now I'm just tracking how many times udelay is called, since that seems to conform more to other timeouts in this file, but did you instead want me to use some time function to keep track of actual real time that expires?

Please wrap your lines of text, as that's one very long line :)

The best way to do this is to do:
	unsigned long timeout;
	...
	timeout = jiffies + msec_to_jiffies(500);	/* Or how ever long you want to wait */
	do {
		do something...
		udelay(10);
	} while (time_before(jiffies, timeout);

	or switch the loop around and do:

	while (something hasn't happened) {
		if (time_after(jjiffies, timeout)) {
			we timed out, handle it here;
			break;
		}
		udelay(10);
	}

That's much better than having to count up a "number" and have to look
to see how long you are sleeping for to determine just exactly how long
you are going to have until the loop times out, as your code did.

Make sense?

greg k-h
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux