[Jython-checkins] jython: Fixed issue 2457.

stefan.richthofer jython-checkins at python.org
Tue Feb 2 18:06:36 EST 2016


https://hg.python.org/jython/rev/cddadb6808c0
changeset:   7889:cddadb6808c0
user:        Stefan Richthofer <stefan.richthofer at gmx.de>
date:        Wed Feb 03 00:06:27 2016 +0100
summary:
  Fixed issue 2457.

files:
  src/org/python/modules/_io/Closer.java |  16 +++++++-------
  1 files changed, 8 insertions(+), 8 deletions(-)


diff --git a/src/org/python/modules/_io/Closer.java b/src/org/python/modules/_io/Closer.java
--- a/src/org/python/modules/_io/Closer.java
+++ b/src/org/python/modules/_io/Closer.java
@@ -3,6 +3,7 @@
 
 import java.lang.ref.WeakReference;
 import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.python.core.PyObject;
 import org.python.core.PySystemState;
@@ -31,6 +32,7 @@
 
     /** Interpreter state that will call {@link #call()} on shutdown. */
     protected PySystemState sys;
+    private AtomicBoolean dismissed = new AtomicBoolean(); //Defaults to false
 
     public Closer(C toClose, PySystemState sys) {
         this.client = new WeakReference<C>(toClose);
@@ -42,10 +44,9 @@
      * Tell the Closer that its services are no longer required. This unhooks it from the shutdown
      * list. Repeated calls are allowed but only the first has any effect.
      */
-    public synchronized void dismiss() {
-        if (sys != null) {
+    public void dismiss() {
+        if (dismissed.compareAndSet(false, true)) {
             sys.unregisterCloser(this);
-            sys = null;
         }
     }
 
@@ -54,10 +55,9 @@
      * "close" method.
      */
     @Override
-    public synchronized Void call() {
-        if (sys != null) {
-            // This will prevent repeated work and dismiss() manipulating the list of closers
-            sys = null;
+    public Void call() {
+    	// This will prevent repeated work and dismiss() manipulating the list of closers
+    	if (dismissed.compareAndSet(false, true)) {
             // Call close on the client (if it still exists)
             C toClose = client.get();
             if (toClose != null) {
@@ -66,4 +66,4 @@
         }
         return null;
     }
-}
\ No newline at end of file
+}

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list