Skip to content

Instantly share code, notes, and snippets.

@jestan
Created December 9, 2011 08:43
Show Gist options
  • Save jestan/1450770 to your computer and use it in GitHub Desktop.
Save jestan/1450770 to your computer and use it in GitHub Desktop.
sctp issue
private boolean scheduleWriteIfNecessary(final SctpChannelImpl channel) {
final Thread currentThread = Thread.currentThread();
final Thread workerThread = thread;
if (currentThread != workerThread) {
if (channel.writeTaskInTaskQueue.compareAndSet(false, true)) {
boolean offered = writeTaskQueue.offer(channel.writeTask);
assert offered;
}
if (!(channel instanceof SctpAcceptedChannel) ||
((SctpAcceptedChannel) channel).bossThread != currentThread) {
final Selector workerSelector = selector;
if (workerSelector != null) {
if (wakenUp.compareAndSet(false, true)) {
workerSelector.wakeup();
}
}
} else {
// A write request can be made from an acceptor thread (boss)
// when a user attempted to write something in:
//
// * channelOpen()
// * channelBound()
// * channelConnected().
//
// In this case, there's no need to wake up the selector because
// the channel is not even registered yet at this moment.
}
return true;
}
return false;
}
@normanmaurer
Copy link

private final Queue<Runnable> registerTaskQueue = new LinkedTransferQueue<Runnable>();
private final Queue<Runnable> writeTaskQueue = new LinkedTransferQueue<Runnable>();

-->
private final Queue registerTaskQueue = new ConcurrentBlockingQueue();
private final Queue writeTaskQueue = new ConcurrentBlockingQueue();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment