|
From: <ls...@us...> - 2010-01-30 20:55:25
|
Revision: 5721
http://jnode.svn.sourceforge.net/jnode/?rev=5721&view=rev
Author: lsantha
Date: 2010-01-30 20:55:18 +0000 (Sat, 30 Jan 2010)
Log Message:
-----------
Findbugs fixes: fixed inconsistent synchronzation. Renamed stack-like methods.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/util/ByteQueue.java
trunk/core/src/core/org/jnode/util/ByteQueueProcessorThread.java
trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java
trunk/gui/src/driver/org/jnode/driver/ps2/PS2ByteChannel.java
trunk/gui/src/driver/org/jnode/driver/ps2/PS2Driver.java
Modified: trunk/core/src/core/org/jnode/util/ByteQueue.java
===================================================================
--- trunk/core/src/core/org/jnode/util/ByteQueue.java 2010-01-30 12:59:18 UTC (rev 5720)
+++ trunk/core/src/core/org/jnode/util/ByteQueue.java 2010-01-30 20:55:18 UTC (rev 5721)
@@ -31,7 +31,6 @@
public class ByteQueue {
// FIXME ... Looking at the way this class is used, I think it may needs an
// atomic drain operation and/or a close operation.
- // FIXME ... The method names are wrong. 'PUSH' and 'POP' is for stacks not queues!!
// FIXME ... Make the ByteQueue API and behavior mirror the Queue API and behavior.
/**
@@ -66,7 +65,7 @@
* made by removing (and discarding) the byte at the head of the queue.
* @param o the byte to be added to the queue.
*/
- public synchronized void push(byte o) {
+ public synchronized void enQueue(byte o) {
data[bottom] = o;
bottom++;
if (bottom >= size) {
@@ -88,7 +87,7 @@
*
* @return the byte removed, or zero if the method call was interrupted.
*/
- public synchronized byte pop() {
+ public synchronized byte deQueue() {
while (top == bottom) { /* Q is empty */
try {
wait();
@@ -110,7 +109,7 @@
/**
* Remove a byte from the head of the queue, blocking with a timeout if data is
- * not immediately available. Unlike {@link #pop()}, this method does <b>not</b>
+ * not immediately available. Unlike {@link #deQueue()}, this method does <b>not</b>
* return zero when interrupted!
*
* @param timeout the maximum time (in milliseconds) to wait for data to become
@@ -119,7 +118,7 @@
* @throws InterruptedException if the method call is interrupted.
* @throws TimeoutException if no data is available within the required time.
*/
- public synchronized byte pop(long timeout)
+ public synchronized byte deQueue(long timeout)
throws TimeoutException, InterruptedException {
while (top == bottom) { /* Q is empty */
wait(timeout);
@@ -140,7 +139,7 @@
/**
* Return the byte at the head of the queue without removing it. If data is
* not immediately available, the method will block (with a timeout) until
- * data is available. Unlike {@link #pop()}, this method does <b>not</b>
+ * data is available. Unlike {@link #deQueue()}, this method does <b>not</b>
* return zero when interrupted!
*
* @param timeout the maximum time (in milliseconds) to wait for data to become
@@ -164,9 +163,15 @@
* Test if there is no data in the queue.
* @return {@code true} if the queue is empty, {@code false} otherwise.
*/
- public boolean isEmpty() {
+ public synchronized boolean isEmpty() {
// FIXME ... this should be synchronized.
return (top == bottom);
}
-
+
+ /**
+ * Clears the queue.
+ */
+ public synchronized void clear() {
+ top = bottom = 0;
+ }
}
Modified: trunk/core/src/core/org/jnode/util/ByteQueueProcessorThread.java
===================================================================
--- trunk/core/src/core/org/jnode/util/ByteQueueProcessorThread.java 2010-01-30 12:59:18 UTC (rev 5720)
+++ trunk/core/src/core/org/jnode/util/ByteQueueProcessorThread.java 2010-01-30 20:55:18 UTC (rev 5721)
@@ -96,7 +96,7 @@
public void run() {
while (!stop) {
try {
- final byte value = queue.pop();
+ final byte value = queue.deQueue();
processor.process(value);
} catch (Exception ex) {
handleException(ex);
Modified: trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2010-01-30 12:59:18 UTC (rev 5720)
+++ trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2010-01-30 20:55:18 UTC (rev 5721)
@@ -165,13 +165,13 @@
// Modifier changed
final int keyCode = usb_kbd_keycode[i + 224];
// It is an extended keycode
- keyCodeQueue.push((byte) KeyboardInterpreter.XT_EXTENDED);
+ keyCodeQueue.enQueue((byte) KeyboardInterpreter.XT_EXTENDED);
if ((old[0] & bit) != 0) {
// Released
- keyCodeQueue.push((byte) (keyCode | KeyboardInterpreter.XT_RELEASE));
+ keyCodeQueue.enQueue((byte) (keyCode | KeyboardInterpreter.XT_RELEASE));
} else {
// Pressed
- keyCodeQueue.push((byte) keyCode);
+ keyCodeQueue.enQueue((byte) keyCode);
}
}
}
@@ -181,7 +181,7 @@
// Key released
final int keyCode = usb_kbd_keycode[old[i] & 0xFF];
if (keyCode > 0) {
- keyCodeQueue.push((byte) (keyCode | KeyboardInterpreter.XT_RELEASE));
+ keyCodeQueue.enQueue((byte) (keyCode | KeyboardInterpreter.XT_RELEASE));
} else {
log.debug("Unknown scancode released " + (old[i] & 0xFF));
}
@@ -190,7 +190,7 @@
// Key pressed
final int keyCode = usb_kbd_keycode[cur[i] & 0xFF];
if (keyCode > 0) {
- keyCodeQueue.push((byte) keyCode);
+ keyCodeQueue.enQueue((byte) keyCode);
} else {
log.debug("Unknown scancode pressed " + (cur[i] & 0xFF));
}
Modified: trunk/gui/src/driver/org/jnode/driver/ps2/PS2ByteChannel.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/ps2/PS2ByteChannel.java 2010-01-30 12:59:18 UTC (rev 5720)
+++ trunk/gui/src/driver/org/jnode/driver/ps2/PS2ByteChannel.java 2010-01-30 20:55:18 UTC (rev 5721)
@@ -44,7 +44,7 @@
* @see org.jnode.system.IRQHandler#handleInterrupt(int)
*/
public void handleScancode(int b) {
- queue.push((byte) b);
+ queue.enQueue((byte) b);
}
/**
@@ -58,7 +58,7 @@
// FIXME: proper exception handling (if end of queue -> IOException)
int i;
for (i = 0; i < dst.remaining(); i++) {
- dst.put(queue.pop());
+ dst.put(queue.deQueue());
}
return i;
}
@@ -71,7 +71,7 @@
if (!isOpen()) {
throw new ClosedChannelException();
}
- return queue.pop(timeout) & 0xFF;
+ return queue.deQueue(timeout) & 0xFF;
}
/**
@@ -116,11 +116,7 @@
* Remove all data from this channel
*/
public void clear() {
- // FIXME ... there is synchronization issues here. The 'isEmpty' method
- // is not synchronized, so we may not see the real state of the queue.
- while (!queue.isEmpty()) {
- queue.pop();
- }
+ queue.clear();
}
}
Modified: trunk/gui/src/driver/org/jnode/driver/ps2/PS2Driver.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/ps2/PS2Driver.java 2010-01-30 12:59:18 UTC (rev 5720)
+++ trunk/gui/src/driver/org/jnode/driver/ps2/PS2Driver.java 2010-01-30 20:55:18 UTC (rev 5721)
@@ -51,7 +51,7 @@
* @see org.jnode.system.IRQHandler#handleInterrupt(int)
*/
public void handleScancode(int b) {
- queue.push((byte) b);
+ queue.enQueue((byte) b);
}
/**
@@ -89,7 +89,7 @@
// FIXME: proper exception handling (if end of queue -> IOException)
int i;
for (i = 0; i < dst.remaining(); i++) {
- dst.put(queue.pop());
+ dst.put(queue.deQueue());
}
return i;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|