Skip to content

Commit

Permalink
Revert "Fix concurrency issue from modifying the selectedKeysSet"
Browse files Browse the repository at this point in the history
This reverts commit b8386a1.
  • Loading branch information
kohlschuetter committed Nov 12, 2023
1 parent f0bafd4 commit 4b2bfc8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ boolean isSelected() {

@Override
public void cancel() {
if (!cancelled.compareAndSet(false, true) || !chann.isOpen()) {
return;
}
sel.prepareRemove(this);
sel.remove(this);
cancelNoRemove();
}

void cancelNoRemove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ final class AFSelector extends AbstractSelector {

private final Set<SelectionKey> selectedKeysSet = new HashSet<>();
private final Set<SelectionKey> selectedKeysPublic = new UngrowableSet<>(selectedKeysSet);
private final Set<SelectionKey> cancelledKeysSet = new HashSet<>();

private PollFd pollFd = null;

Expand Down Expand Up @@ -113,7 +112,6 @@ private int select0(int timeout) throws IOException {
throw new ClosedSelectorException();
}
pfd = pollFd = initPollFd(pollFd);
performRemove();
selectedKeysSet.clear();
}
int num;
Expand Down Expand Up @@ -301,23 +299,6 @@ synchronized void remove(AFSelectionKey key) {
pollFd = null;
}

void prepareRemove(AFSelectionKey key) {
synchronized (cancelledKeysSet) {
cancelledKeysSet.add(key);
}
}

void performRemove() {
synchronized (cancelledKeysSet) {
for (SelectionKey key : cancelledKeysSet) {
selectedKeysSet.remove(key);
deregister((AFSelectionKey) key);
pollFd = null;
}
cancelledKeysSet.clear();
}
}

private void deregister(AFSelectionKey key) {
// super.deregister unnecessarily casts SelectionKey to AbstractSelectionKey, and
// ((AbstractSelectableChannel)key.channel()).removeKey(key); is not visible.
Expand Down

0 comments on commit 4b2bfc8

Please sign in to comment.