Update of /cvsroot/freenet/freenet/src/freenet/transport
In directory sc8-pr-cvs1:/tmp/cvs-serv10878/src/freenet/transport
Modified Files:
AbstractSelectorLoop.java
Log Message:
Reduce locking. Profiler said that the *SL threads could be blocked here for
significant amounts of time.
Index: AbstractSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/AbstractSelectorLoop.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -w -r1.81 -r1.82
--- AbstractSelectorLoop.java 15 Oct 2003 00:48:37 -0000 1.81
+++ AbstractSelectorLoop.java 16 Oct 2003 09:39:56 -0000 1.82
@@ -419,35 +419,55 @@
* channels are closed
* now this cancel()'s the keys and doesn't notify the close thread --zab
*/
- private void handleCloseQueuePipe()
- {
-
- synchronized(closeQueue) {
-
+ private void handleCloseQueuePipe() {
+ //We aren't synchronized on preCloseQueue here but it doesn't mean the
end of the
+ //world that we queue the close a little while later instead (as of
+ //2003-10-16 this method is called by three selector threads).
+ //This extra check is done to avoid the
'synchronized(preCloseQueueObject)'
+ //scope below if it probably wouldn't gain us something to enter it
+ //(locking optimization)
+ if(preCloseQueue.isEmpty())
+ return;
+
+ //Remove all entries from the preCloseQueue into a local queue
+ //in order to prevent other threads from beeing blocked on
preCloseQueue
+ //during the processing below (locking optimization)
+ LinkedList workList = new LinkedList();
synchronized(preCloseQueueObject) {
- //boolean wasEmpty = closeQueue.isEmpty();
- //boolean itemAdded = false;
while(!preCloseQueue.isEmpty()) {
- ClosePair current =
(ClosePair)preCloseQueue.removeFirst();
- if (current.sc != null)
- if
(tcpConnection.getRSL().keyFor(current.sc)!=null) {
-
tcpConnection.getRSL().keyFor(current.sc).cancel();
- closeQueue.addLast(current);
- } else
- if
(tcpConnection.getWSL().keyFor(current.sc)!=null) {
-
tcpConnection.getWSL().keyFor(current.sc).cancel();
- closeQueue.addLast(current);
- } else
- closeQueue.addLast(current);
//key is not registered anywhere?
+ workList.addLast(preCloseQueue.removeFirst());
}
- // itemAdded = true;
}
- /*if(wasEmpty && itemAdded)
- closeQueue.notify();*/
-
-
+ //Cancel the keys that have been queued for closing on all ?known?
+ //selector threads
+ Iterator it = workList.iterator();
+ ClosePair current;
+ while(it.hasNext()){
+ current = (ClosePair)it.next();
+ if ( current.sc != null) {
+ SelectionKey k =
tcpConnection.getRSL().keyFor(current.sc);
+ if (k != null) {
+ k.cancel();
+ } else {
+ k = tcpConnection.getWSL().keyFor(current.sc);
+ if (k != null) {
+ k.cancel();
+ }
+ }
+ }
+ }
+ //An extra check here to avoid entering the 'synchronized(closeQueue)'
scope below
+ //if we dont actually need to (locking optimization)
+ if(workList.isEmpty())
+ return;
+
+ //Finished processing all the closerequests we popped from the
+ //preCloseQueue earlier in this method, now queue them for actual
closing
+ //From here the closeThread will pick them up at its leisure...
+ synchronized (closeQueue) {
+ closeQueue.addAll(workList);
}
}
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs