Greg: This patch fixes a problem with my recent set of locking changes for USB. The problem is that rw-semaphores don't have the semantics I need. I need something where, if the semaphore is locked for reading and a writer is waiting for the lock, another reader will be granted a readlock immediately. That's because there are several places where a thread holding the readlock will acquire the readlock again, in a nested or recursive fashion. If a writer is waiting for the first readlock to be released, the standard semantics will yield deadlock.
This patch implements those alternate semantics by putting writers on a separate wait queue. It's a little bit awkward and has a definite roll-you-own flavor, but it works. Please apply. Alan Stern Signed-off-by: Alan Stern <[EMAIL PROTECTED]> ===== drivers/usb/core/usb.c 1.281 vs edited ===== --- 1.281/drivers/usb/core/usb.c Wed Jun 30 09:44:26 2004 +++ edited/drivers/usb/core/usb.c Wed Jul 7 15:47:23 2004 @@ -64,6 +64,7 @@ /* Not honored on modular build */ static DECLARE_RWSEM(usb_all_devices_rwsem); +static DECLARE_WAIT_QUEUE_HEAD(usb_all_devices_wqh); static int generic_probe (struct device *dev) @@ -933,6 +934,7 @@ { up(&udev->serialize); up_read(&usb_all_devices_rwsem); + wake_up(&usb_all_devices_wqh); } /** @@ -940,10 +942,15 @@ * * This is necessary when registering a new driver or probing a bus, * since the driver-model core may try to use any usb_device. + * + * Unfortunately we have to use a separate wait queue, because we need + * to make sure that a thread waiting for a writelock won't block other + * threads from acquiring a readlock. */ void usb_lock_all_devices(void) { - down_write(&usb_all_devices_rwsem); + wait_event(usb_all_devices_wqh, + down_write_trylock(&usb_all_devices_rwsem)); } /** @@ -952,6 +959,7 @@ void usb_unlock_all_devices(void) { up_write(&usb_all_devices_rwsem); + wake_up(&usb_all_devices_wqh); } ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel