You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by re...@apache.org on 2009/10/16 04:50:38 UTC
svn commit: r825746 -
/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
Author: regisxu
Date: Fri Oct 16 02:50:38 2009
New Revision: 825746
URL: http://svn.apache.org/viewvc?rev=825746&view=rev
Log:
partial fix for HARMONY-6312: Concurrency problems in NIO
- change type of "keys" to SelectionKeyImpl[]
- minor doc fix
Modified:
harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java?rev=825746&r1=825745&r2=825746&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java Fri Oct 16 02:50:38 2009
@@ -72,7 +72,7 @@
private static class KeysLock {}
final Object keysLock = new KeysLock();
- private SelectionKey[] keys = new SelectionKey[1];
+ private SelectionKeyImpl[] keys = new SelectionKeyImpl[1];
private final Set<SelectionKey> mutableKeys = new HashSet<SelectionKey>();
@@ -144,7 +144,7 @@
// register sink channel
readableFDs[0] = sourcefd;
- keys[0] = source.keyFor(this);
+ keys[0] = (SelectionKeyImpl) source.keyFor(this);
// index it
keysToReadableFDs[0] = 0;
@@ -178,7 +178,7 @@
private void ensureCommonCapacity(int c) {
// TODO: rewrite array handling as some internal class
if (c >= keys.length) {
- SelectionKey[] newKeys = new SelectionKey[(keys.length + 1) << 1];
+ SelectionKeyImpl[] newKeys = new SelectionKeyImpl[(keys.length + 1) << 1];
System.arraycopy(keys, 0, newKeys, 0, keys.length);
keys = newKeys;
}
@@ -244,7 +244,7 @@
* key to add
* @return index in the storage
*/
- private int addKey(SelectionKey sk) {
+ private int addKey(SelectionKeyImpl sk) {
lastKeyIndex++;
int c = lastKeyIndex;
@@ -299,8 +299,8 @@
* @param sk
* key to delete
*/
- private void delKey(SelectionKey sk) {
- int index = ((SelectionKeyImpl) sk).getIndex();
+ private void delKey(SelectionKeyImpl sk) {
+ int index = sk.getIndex();
// === deleting the key and FDs
@@ -331,7 +331,7 @@
keys[lastKeyIndex] = null;
// update key index
- ((SelectionKeyImpl) keys[index]).setIndex(index);
+ keys[index].setIndex(index);
// the key in the new position references the same FDs
keysToReadableFDs[index] = keysToReadableFDs[lastKeyIndex];
@@ -393,9 +393,10 @@
synchronized (this) {
synchronized (unmodifiableKeys) {
synchronized (selectedKeys) {
- delKey(sk);
- int newIndex = addKey(sk);
- ((SelectionKeyImpl)sk).setIndex(newIndex);
+ SelectionKeyImpl ski = (SelectionKeyImpl) sk;
+ delKey(ski);
+ int newIndex = addKey(ski);
+ ski.setIndex(newIndex);
}
}
}
@@ -498,7 +499,7 @@
synchronized (cancelledKeys) {
if (cancelledKeys.size() > 0) {
for (SelectionKey currentkey : cancelledKeys) {
- delKey(currentkey);
+ delKey((SelectionKeyImpl)currentkey);
mutableKeys.remove(currentkey);
deregister((AbstractSelectionKey) currentkey);
if (mutableSelectedKeys.remove(currentkey)) {
@@ -544,9 +545,9 @@
if (flags[i] == NA) {
continue;
}
- SelectionKeyImpl key = (SelectionKeyImpl) (i >= readableKeysCount ? keys[writableFDsToKeys[i
+ SelectionKeyImpl key = i >= readableKeysCount ? keys[writableFDsToKeys[i
- readableKeysCount]]
- : keys[readableFDsToKeys[i]]);
+ : keys[readableFDsToKeys[i]];
if (null == key) {
continue;
@@ -594,14 +595,14 @@
}
/*
- * Assumes calling thread holds locks on 'this', 'keysSet', and 'selectedKeys'.
+ * Assumes calling thread holds locks on 'this', 'unmodifiableKeys', and 'selectedKeys'.
*/
private void doCancel() {
Set<SelectionKey> cancelledKeys = cancelledKeys();
synchronized (cancelledKeys) {
if (cancelledKeys.size() > 0) {
for (SelectionKey currentkey : cancelledKeys) {
- delKey(currentkey);
+ delKey((SelectionKeyImpl)currentkey);
mutableKeys.remove(currentkey);
deregister((AbstractSelectionKey) currentkey);
mutableSelectedKeys.remove(currentkey);