Hi Oliver, Oliver Neukum <[EMAIL PROTECTED]> writes: > Am Samstag, 13. M�rz 2004 15:18 schrieb Juergen Stuber: >> Oliver Neukum <[EMAIL PROTECTED]> writes: >> >> >> >> + atomic_t interrupt_in_running; >> >> + atomic_t interrupt_in_done; >> > >> > what use are these atomic declarations? >> >> good question. >> I got this pattern from the use of write_busy in usb-skeleton.c . >> I think it is a safe programming style for concurrently accessed >> variables, but that it isn't strictly necessary if you only read >> and set byte values. > > The problem is that it leads to sloppy thinking about locking. People > tend to assume that if they use enough atomic_t races vanish > automagically.
I try not to be in this category, though it is not easy. > Code like this: > + atomic_set (&dev->interrupt_in_running, 1); > + atomic_set (&dev->interrupt_in_done, 0); > + retval = usb_submit_urb (dev->interrupt_in_urb, GFP_KERNEL); > > is potentially racy. It seems to me that you'd rather be clearer with > code like this: > > dev->interrupt_in_running = 1; > wmb(); > dev->interrupt_in_done = 0; That is not the case here, in fact the order of the two assignments is not important, and they don't protect any other resources. interrupt_in_done is used to signal that the completion handler has run, in order to wake up a waiting process. interrupt_in_running is used to avoid unlinking an URB that has not been submitted, and to avoid resubmitting when unlinking in close or disconnect. I think the latter is no longer needed with proper handling of error codes in the completion handler, though it might be less brittle. The former just avoids spurious error messages in the log. Both should be ok if their values arrive before open returns and before the first run of the completion handler. However, I am not sure why this should be assured, other than that it is a rather long time. How about putting a barrier before the usb_submit_urb()? J�rgen -- J�rgen Stuber <[EMAIL PROTECTED]> http://www.loria.fr/~stuber/ ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
