commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1130000 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net: LocalSocketEndpoint.java SocketEndpoint.java
Date Wed, 01 Jun 2011 05:01:14 GMT
Author: mturk
Date: Wed Jun  1 05:01:14 2011
New Revision: 1130000

URL: http://svn.apache.org/viewvc?rev=1130000&view=rev
Log:
Axe endpoint locking. API that was guarded is meant to be used from a single thread anyhow

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java?rev=1130000&r1=1129999&r2=1130000&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
Wed Jun  1 05:01:14 2011
@@ -40,8 +40,6 @@ public class LocalSocketEndpoint extends
     private LocalSocketDescriptor  sd;
     private SelectionKeyImpl       key;
     private boolean                blocking = false;
-    // Lock for registration and configureBlocking operations
-    private final Object           synclock = new Object();
 
     private static native int nonblock0(int fd, boolean block);
 
@@ -75,20 +73,16 @@ public class LocalSocketEndpoint extends
     public boolean isBlocking()
         throws IOException
     {
-        synchronized (synclock) {
-            return blocking;
-        }
+        return blocking;
     }
 
     @Override
     public boolean isRegistered()
     {
-        synchronized (synclock) {
-            if (key != null && key.selected)
-                return true;
-            else
-                return false;
-        }
+        if (key != null && key.selected)
+            return true;
+        else
+            return false;
     }
 
     @Override
@@ -99,16 +93,14 @@ public class LocalSocketEndpoint extends
     {
         if (sd.closed())
             throw new ClosedDescriptorException();
-        synchronized (synclock) {
-            if (key != null && key.selected)
-                throw new IllegalBlockingModeException();
-            if (blocking == block)
-                return sd;
-            int rc = nonblock0(sd.fd(), block);
-            if (rc != 0)
-                throw new SocketException(Status.describe(rc));
-            blocking = block;
-        }
+        if (key != null && key.selected)
+            throw new IllegalBlockingModeException();
+        if (blocking == block)
+            return sd;
+        int rc = nonblock0(sd.fd(), block);
+        if (rc != 0)
+            throw new SocketException(Status.describe(rc));
+        blocking = block;
         return sd;
     }
 
@@ -117,33 +109,29 @@ public class LocalSocketEndpoint extends
     public void close()
         throws IOException
     {
-        synchronized (synclock) {
-            if (sd.valid()) {
-                if (key != null && key.selected) {
-                    try {
-                        key.cancel();
-                    } catch (Exception e) {
-                        // Ignore selector exceptions
-                    }
+        if (sd.valid()) {
+            if (key != null && key.selected) {
+                try {
+                    key.cancel();
+                } catch (Exception e) {
+                    // Ignore selector exceptions
                 }
-                sd.close();
-            }
-            if (key != null) {
-                key.reset();
-                key = null;
             }
+            sd.close();
+        }
+        if (key != null) {
+            key.reset();
+            key = null;
         }
     }
 
     @Override
     public SelectionKey keyFor(Selector selector)
     {
-        synchronized (synclock) {
-            if (key != null && key.selector == selector)
-                return key;
-            else
-                return null;
-        }
+        if (key != null && key.selector == selector)
+            return key;
+        else
+            return null;
     }
 
     @Override
@@ -158,19 +146,17 @@ public class LocalSocketEndpoint extends
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
-        synchronized (synclock) {
-            if (key == null)
-                key = new SelectionKeyImpl(sel, this);
-            if (key.selector != sel)
-                throw new IllegalSelectorException();
-            if (att != null)
-                key.attach(att);
-            if (key.selected)
-                return key;
-            if (ops != 0)
-                key.ievents = ops;
-            return sel.queue(key, sd);
-        }
+        if (key == null)
+            key = new SelectionKeyImpl(sel, this);
+        if (key.selector != sel)
+            throw new IllegalSelectorException();
+        if (att != null)
+            key.attach(att);
+        if (key.selected)
+            return key;
+        if (ops != 0)
+            key.ievents = ops;
+        return sel.queue(key, sd);
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1130000&r1=1129999&r2=1130000&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Wed Jun  1 05:01:14 2011
@@ -36,8 +36,6 @@ public class SocketEndpoint extends Endp
     private SocketDescriptor  sd;
     private SelectionKeyImpl  key;
     private boolean           blocking = false;
-    // Lock for registration and configureBlocking operations
-    private final Object      synclock = new Object();
 
     private static native int nonblock0(int fd, boolean block);
     
@@ -70,12 +68,10 @@ public class SocketEndpoint extends Endp
     @Override
     public boolean isRegistered()
     {
-        synchronized (synclock) {
-            if (key != null && key.selected)
-                return true;
-            else
-                return false;
-        }
+        if (key != null && key.selected)
+            return true;
+        else
+            return false;
     }
 
     @Override
@@ -85,17 +81,15 @@ public class SocketEndpoint extends Endp
                IOException
     {
         if (sd.closed())
-            throw new ClosedDescriptorException();
-        synchronized (synclock) {
-            if (key != null && key.selected)
-                throw new IllegalBlockingModeException();
-            if (blocking == block)
-                return sd;
-            int rc = nonblock0(sd.fd(), block);
-            if (rc != 0)
-                throw new SocketException(Status.describe(rc));
-            blocking = block;
-        }
+        throw new ClosedDescriptorException();
+        if (key != null && key.selected)
+            throw new IllegalBlockingModeException();
+        if (blocking == block)
+            return sd;
+        int rc = nonblock0(sd.fd(), block);
+        if (rc != 0)
+            throw new SocketException(Status.describe(rc));
+        blocking = block;
         return sd;
     }
 
@@ -103,42 +97,36 @@ public class SocketEndpoint extends Endp
     public boolean isBlocking()
         throws IOException
     {
-        synchronized (synclock) {
-            return blocking;
-        }
+        return blocking;
     }
 
     @Override
     public void close()
         throws IOException
     {
-        synchronized (synclock) {
-            if (sd.valid()) {
-                if (key != null && key.selected) {
-                    try {
-                        key.cancel();
-                    } catch (Exception e) {
-                        // Ignore selector exceptions
-                    }
+        if (sd.valid()) {
+            if (key != null && key.selected) {
+                try {
+                    key.cancel();
+                } catch (Exception e) {
+                    // Ignore selector exceptions
                 }
-                sd.close();
-            }
-            if (key != null) {
-                key.reset();
-                key = null;
             }
+            sd.close();
+        }
+        if (key != null) {
+            key.reset();
+            key = null;
         }
     }
 
     @Override
     public SelectionKey keyFor(Selector selector)
     {
-        synchronized (synclock) {
-            if (key != null && key.selector == selector)
-                return key;
-            else
-                return null;
-        }
+        if (key != null && key.selector == selector)
+            return key;
+        else
+            return null;
     }
 
     @Override
@@ -153,19 +141,17 @@ public class SocketEndpoint extends Endp
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
-        synchronized (synclock) {
-            if (key == null)
-                key = new SelectionKeyImpl(sel, this);
-            if (key.selector != sel)
-                throw new IllegalSelectorException();
-            if (att != null)
-                key.attach(att);
-            if (key.selected)
-                return key;
-            if (ops != 0)
-                key.ievents = ops;
-            return sel.queue(key, sd);
-        }
+        if (key == null)
+            key = new SelectionKeyImpl(sel, this);
+        if (key.selector != sel)
+            throw new IllegalSelectorException();
+        if (att != null)
+            key.attach(att);
+        if (key.selected)
+            return key;
+        if (ops != 0)
+            key.ievents = ops;
+        return sel.queue(key, sd);
     }
 
 }



Mime
View raw message