From 17a62649faa31b474c9b48946fe5a47a440c0de3 Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Thu, 24 Apr 2014 22:10:51 -0500 Subject: [PATCH 1/4] Update AbstractIrpQueue.java added synchronized blocks to thread control --- src/main/java/org/usb4java/javax/AbstractIrpQueue.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java index 39add76..9d5abfb 100644 --- a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java +++ b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java @@ -58,7 +58,7 @@ abstract class AbstractIrpQueue * @param irp * The control IRP to queue. */ - public final void add(final T irp) + public final synchronized void add(final T irp) { this.irps.add(irp); @@ -92,7 +92,7 @@ final void process() // if present). if (irp == null) { - this.processor = null; + synchronized { this.processor = null; } } else { @@ -153,7 +153,7 @@ final void process() * aborted. This method returns as soon as no more IRPs are in the queue and * no more are processed. */ - public final void abort() + public final synchronized void abort() { this.aborting = true; this.irps.clear(); @@ -180,7 +180,7 @@ public final void abort() * * @return True if queue is busy, false if not. */ - public final boolean isBusy() + public final synchronized boolean isBusy() { return !this.irps.isEmpty() || this.processor != null; } From 626be960475fb9a4bc329b44f1c9cdfbc5653fe2 Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Thu, 24 Apr 2014 22:12:55 -0500 Subject: [PATCH 2/4] Update AbstractIrpQueue.java added this --- src/main/java/org/usb4java/javax/AbstractIrpQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java index 9d5abfb..422e555 100644 --- a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java +++ b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java @@ -92,7 +92,7 @@ final void process() // if present). if (irp == null) { - synchronized { this.processor = null; } + synchronized(this) { this.processor = null; } } else { From 871993771b299b547f196d8e5a1e51fbe578e248 Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Thu, 24 Apr 2014 23:24:58 -0500 Subject: [PATCH 3/4] Update AbstractIrpQueue.java woops, one more sync spot --- src/main/java/org/usb4java/javax/AbstractIrpQueue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java index 422e555..85f1231 100644 --- a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java +++ b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java @@ -92,7 +92,7 @@ final void process() // if present). if (irp == null) { - synchronized(this) { this.processor = null; } + synchronized(this) { this.processor = null; } } else { @@ -111,7 +111,7 @@ final void process() // Get next IRP and mark the thread as closing before sending // the events for the previous IRP final T nextIrp = this.irps.poll(); - if (nextIrp == null) this.processor = null; + if (nextIrp == null) synchronized(this) { this.processor = null; } // Finish the previous IRP irp.complete(); From 551e85a823a3f86e2ec190877e30ba66cc65d05d Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Sat, 26 Apr 2014 10:51:14 -0500 Subject: [PATCH 4/4] removed useless sync point --- .../org/usb4java/javax/AbstractIrpQueue.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java index 85f1231..0de6cb6 100644 --- a/src/main/java/org/usb4java/javax/AbstractIrpQueue.java +++ b/src/main/java/org/usb4java/javax/AbstractIrpQueue.java @@ -58,24 +58,26 @@ abstract class AbstractIrpQueue * @param irp * The control IRP to queue. */ - public final synchronized void add(final T irp) + public final void add(final T irp) { this.irps.add(irp); // Start the queue processor if not already running. if (this.processor == null) { - this.processor = new Thread(new Runnable() - { - @Override - public void run() - { - process(); + synchronized(this) { + if (this.processor == null) { + this.processor = new Thread(new Runnable() { + @Override + public void run() { + process(); + } + }); + this.processor.setDaemon(true); + this.processor.setName("usb4java IRP Queue Processor"); + this.processor.start(); } - }); - this.processor.setDaemon(true); - this.processor.setName("usb4java IRP Queue Processor"); - this.processor.start(); + } } }