From: Mike C. <mc...@us...> - 2008-08-18 18:14:56
|
Update of /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv21247 Modified Files: Mutex.java WindowsPipeOsImp.java Log Message: when using interrupt IN, mutexs where being acquired for long periods of time, blocking the update thread (java jdk1.6.0) for long periods of time, removed mutex on interrupt in. Had to modify Mutex to allow unlock without lock for proper performance in exception conditions Index: WindowsPipeOsImp.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/WindowsPipeOsImp.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WindowsPipeOsImp.java 5 Aug 2008 16:26:52 -0000 1.2 --- WindowsPipeOsImp.java 18 Aug 2008 18:14:52 -0000 1.3 *************** *** 226,230 **** // lock the access to the libusb - JavaxUsb.getMutex().acquire(); // log.debug("Entering submitIrp, epType: "+epType+" epDir: "+epDir+" timeout: "+timeout+" ms"); --- 226,229 ---- *************** *** 233,238 **** switch (epType) { ! case UsbConst.ENDPOINT_TYPE_BULK : ! if (epDir == UsbConst.ENDPOINT_DIRECTION_OUT) { --- 232,236 ---- switch (epType) { ! case UsbConst.ENDPOINT_TYPE_BULK : if (epDir == UsbConst.ENDPOINT_DIRECTION_OUT) { *************** *** 248,271 **** { byte[] buf; ! int toWrite = ! Math.min(requested - written, chunkSize); buf = new byte[toWrite]; System.arraycopy(data, written, buf, 0, toWrite); written += toWrite; - res = Libusb.usb_bulk_write( - handle, - getEndpointAddress(), - buf, - timeout); if (log.isDebugEnabled()) ! log.debug( ! "Called bulk_write with buffer of size " ! + buf.length + ", res = " + res); if (res != toWrite) { result = res; - break; } --- 246,264 ---- { byte[] buf; ! int toWrite = Math.min(requested - written, chunkSize); buf = new byte[toWrite]; System.arraycopy(data, written, buf, 0, toWrite); written += toWrite; + JavaxUsb.getMutex().acquire(); //FIXME not sure if this is required + res = Libusb.usb_bulk_write(handle,getEndpointAddress(),buf,timeout); + JavaxUsb.getMutex().release(); //FIXME not sure if this is required + if (log.isDebugEnabled()) ! log.debug("Called bulk_write with buffer of size "+ buf.length + ", res = " + res); if (res != toWrite) { result = res; break; } *************** *** 275,308 **** { action = "bulk read"; ! ! // byte[] bytes = new byte[64]; ! result = ! Libusb.usb_bulk_read( ! handle, ! getEndpointAddress(), ! irp.getData(), ! timeout); ! ! // fixme: remove this debug msg ! log.debug("---------- result: " + result); } - break; ! case UsbConst.ENDPOINT_TYPE_INTERRUPT : ! if (epDir == UsbConst.ENDPOINT_DIRECTION_OUT) { action = "interrupt write"; result = Libusb.usb_interrupt_write(handle,getEndpointAddress(),irp.getData(),timeout); ! } else if (epDir == UsbConst.ENDPOINT_DIRECTION_IN) { action = "interrupt read"; result = Libusb.usb_interrupt_read(handle,getEndpointAddress(),irp.getData(),timeout); } break; ! default : throw new RuntimeException("WindowsPipeOsImp.submitIrp: end point ("+epType+") type not (yet) supported!"); } --- 268,294 ---- { action = "bulk read"; ! JavaxUsb.getMutex().acquire(); //FIXME not sure if this is required ! result = Libusb.usb_bulk_read(handle,getEndpointAddress(),irp.getData(),timeout); ! JavaxUsb.getMutex().release(); //FIXME not sure if this is required } break; ! case UsbConst.ENDPOINT_TYPE_INTERRUPT : if (epDir == UsbConst.ENDPOINT_DIRECTION_OUT) { action = "interrupt write"; + JavaxUsb.getMutex().acquire(); //FIXME not sure if this is required result = Libusb.usb_interrupt_write(handle,getEndpointAddress(),irp.getData(),timeout); ! JavaxUsb.getMutex().release(); //FIXME not sure if this is required } else if (epDir == UsbConst.ENDPOINT_DIRECTION_IN) { action = "interrupt read"; + // don't use a mutex here because a long time may elapse before getting a response + // and FIXME, not sure a mutex is required anyway for this action result = Libusb.usb_interrupt_read(handle,getEndpointAddress(),irp.getData(),timeout); } break; ! default : throw new RuntimeException("WindowsPipeOsImp.submitIrp: end point ("+epType+") type not (yet) supported!"); } Index: Mutex.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/Mutex.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Mutex.java 9 Jan 2006 21:12:37 -0000 1.1.1.1 --- Mutex.java 18 Aug 2008 18:14:52 -0000 1.2 *************** *** 80,90 **** { if (owner != Thread.currentThread()) ! throw new IllegalStateException( ! "Thread calling release() doesn't own mutex"); if (--lock_count <= 0) { owner = null; ! notify(); } } --- 80,91 ---- { if (owner != Thread.currentThread()) ! return; ! // throw new IllegalStateException( ! // "Thread calling release() doesn't own mutex"); if (--lock_count <= 0) { owner = null; ! notifyAll(); } } |