Skip to content

Usb4java javax 1.2.1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/main/java/org/usb4java/javax/AbstractIrpQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ public final void add(final T 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();
}
}
}

Expand All @@ -92,7 +94,7 @@ final void process()
// if present).
if (irp == null)
{
this.processor = null;
synchronized(this) { this.processor = null; }
}
else
{
Expand All @@ -111,7 +113,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();
Expand Down Expand Up @@ -153,7 +155,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();
Expand All @@ -180,7 +182,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;
}
Expand Down