23 * questions.
24 */
25
26 /*
27 */
28
29
30 package sun.nio.ch;
31
32 import java.nio.channels.spi.SelectorProvider;
33 import java.nio.channels.Selector;
34 import java.nio.channels.ClosedSelectorException;
35 import java.nio.channels.Pipe;
36 import java.nio.channels.SelectableChannel;
37 import java.io.IOException;
38 import java.nio.channels.CancelledKeyException;
39 import java.util.List;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.Iterator;
43 import sun.misc.ManagedLocalsThread;
44
45 /**
46 * A multi-threaded implementation of Selector for Windows.
47 *
48 * @author Konstantin Kladko
49 * @author Mark Reinhold
50 */
51
52 final class WindowsSelectorImpl extends SelectorImpl {
53 // Initial capacity of the poll array
54 private final int INIT_CAP = 8;
55 // Maximum number of sockets for select().
56 // Should be INIT_CAP times a power of 2
57 private static final int MAX_SELECTABLE_FDS = 1024;
58
59 // The list of SelectableChannels serviced by this Selector. Every mod
60 // MAX_SELECTABLE_FDS entry is bogus, to align this array with the poll
61 // array, where the corresponding entry is occupied by the wakeupSocket
62 private SelectionKeyImpl[] channelArray = new SelectionKeyImpl[INIT_CAP];
63
387 selectedKeys.add(sk);
388 me.updateCount = updateCount;
389 numKeysUpdated++;
390 }
391 } else { // The readyOps have been set; now add
392 sk.channel.translateAndUpdateReadyOps(rOps, sk);
393 if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
394 selectedKeys.add(sk);
395 me.updateCount = updateCount;
396 numKeysUpdated++;
397 }
398 }
399 me.clearedCount = updateCount;
400 }
401 }
402 return numKeysUpdated;
403 }
404 }
405
406 // Represents a helper thread used for select.
407 private final class SelectThread extends ManagedLocalsThread {
408 private final int index; // index of this thread
409 final SubSelector subSelector;
410 private long lastRun = 0; // last run number
411 private volatile boolean zombie;
412 // Creates a new thread
413 private SelectThread(int i) {
414 this.index = i;
415 this.subSelector = new SubSelector(i);
416 //make sure we wait for next round of poll
417 this.lastRun = startLock.runsCounter;
418 }
419 void makeZombie() {
420 zombie = true;
421 }
422 boolean isZombie() {
423 return zombie;
424 }
425 public void run() {
426 while (true) { // poll loop
427 // wait for the start of poll. If this thread has become
428 // redundant, then exit.
429 if (startLock.waitForStart(this))
430 return;
431 // call poll()
432 try {
433 subSelector.poll(index);
|
23 * questions.
24 */
25
26 /*
27 */
28
29
30 package sun.nio.ch;
31
32 import java.nio.channels.spi.SelectorProvider;
33 import java.nio.channels.Selector;
34 import java.nio.channels.ClosedSelectorException;
35 import java.nio.channels.Pipe;
36 import java.nio.channels.SelectableChannel;
37 import java.io.IOException;
38 import java.nio.channels.CancelledKeyException;
39 import java.util.List;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.Iterator;
43
44 /**
45 * A multi-threaded implementation of Selector for Windows.
46 *
47 * @author Konstantin Kladko
48 * @author Mark Reinhold
49 */
50
51 final class WindowsSelectorImpl extends SelectorImpl {
52 // Initial capacity of the poll array
53 private final int INIT_CAP = 8;
54 // Maximum number of sockets for select().
55 // Should be INIT_CAP times a power of 2
56 private static final int MAX_SELECTABLE_FDS = 1024;
57
58 // The list of SelectableChannels serviced by this Selector. Every mod
59 // MAX_SELECTABLE_FDS entry is bogus, to align this array with the poll
60 // array, where the corresponding entry is occupied by the wakeupSocket
61 private SelectionKeyImpl[] channelArray = new SelectionKeyImpl[INIT_CAP];
62
386 selectedKeys.add(sk);
387 me.updateCount = updateCount;
388 numKeysUpdated++;
389 }
390 } else { // The readyOps have been set; now add
391 sk.channel.translateAndUpdateReadyOps(rOps, sk);
392 if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
393 selectedKeys.add(sk);
394 me.updateCount = updateCount;
395 numKeysUpdated++;
396 }
397 }
398 me.clearedCount = updateCount;
399 }
400 }
401 return numKeysUpdated;
402 }
403 }
404
405 // Represents a helper thread used for select.
406 private final class SelectThread extends Thread {
407 private final int index; // index of this thread
408 final SubSelector subSelector;
409 private long lastRun = 0; // last run number
410 private volatile boolean zombie;
411 // Creates a new thread
412 private SelectThread(int i) {
413 super(null, null, "SelectorHelper", 0, false);
414 this.index = i;
415 this.subSelector = new SubSelector(i);
416 //make sure we wait for next round of poll
417 this.lastRun = startLock.runsCounter;
418 }
419 void makeZombie() {
420 zombie = true;
421 }
422 boolean isZombie() {
423 return zombie;
424 }
425 public void run() {
426 while (true) { // poll loop
427 // wait for the start of poll. If this thread has become
428 // redundant, then exit.
429 if (startLock.waitForStart(this))
430 return;
431 // call poll()
432 try {
433 subSelector.poll(index);
|