tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r578963 - in /tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net: NioBlockingSelector.java NioEndpoint.java
Date Mon, 24 Sep 2007 20:56:33 GMT
Author: fhanik
Date: Mon Sep 24 13:56:31 2007
New Revision: 578963

URL: http://svn.apache.org/viewvc?rev=578963&view=rev
Log:
optimize pollers, don't lock into a blocking select if there are other things for the thread
to do

Modified:
    tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioBlockingSelector.java
    tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioBlockingSelector.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioBlockingSelector.java?rev=578963&r1=578962&r2=578963&view=diff
==============================================================================
--- tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioBlockingSelector.java (original)
+++ tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioBlockingSelector.java Mon Sep
24 13:56:31 2007
@@ -207,8 +207,7 @@
         }
 
         public void wakeup() {
-            int i = wakeupCounter.addAndGet(1);
-            if (i==1) selector.wakeup();
+            if (wakeupCounter.addAndGet(1)==0) selector.wakeup();
         }
 
         public void cancel(SelectionKey sk, KeyAttachment key, int ops){
@@ -301,8 +300,10 @@
                         int i = wakeupCounter.get();
                         if (i>0) 
                             keyCount = selector.selectNow();
-                        else
+                        else {
+                            wakeupCounter.set(-1);
                             keyCount = selector.select(1000);
+                        }
                         wakeupCounter.set(0);
                         if (!run) break;
                     }catch ( NullPointerException x ) {

Modified: tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=578963&r1=578962&r2=578963&view=diff
==============================================================================
--- tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/sandbox/gdev6x/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Sep 24 13:56:31
2007
@@ -1342,7 +1342,7 @@
         
         public void addEvent(Runnable event) {
             events.offer(event);
-            if ( wakeupCounter.incrementAndGet() < 3 ) selector.wakeup();
+            if ( wakeupCounter.incrementAndGet() == 0 ) selector.wakeup();
         }
         
         public void cometInterest(NioChannel socket) {
@@ -1459,7 +1459,14 @@
                     int keyCount = 0;
                     try {
                         if ( !close ) {
-                            keyCount = selector.select(selectorTimeout);
+                            if (wakeupCounter.get()>0) {
+                                //if we are here, means we have other stuff to do
+                                //do a non blocking select
+                                keyCount = selector.selectNow();
+                            }else {
+                                wakeupCounter.set( -1);
+                                keyCount = selector.select(selectorTimeout);
+                            }
                             wakeupCounter.set(0);
                         }
                         if (close) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message