Author: nextgens
Date: 2008-07-16 13:20:29 +0000 (Wed, 16 Jul 2008)
New Revision: 21146

Modified:
   trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
   trunk/freenet/src/freenet/node/updater/NodeUpdater.java
Log:
Hopefully fix a few locking-related bugs in the updater. (backport of r21089 
and r21090 in a different way)

NEEDS TESTING

Modified: trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java       
2008-07-16 12:43:00 UTC (rev 21145)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java       
2008-07-16 13:20:29 UTC (rev 21146)
@@ -52,9 +52,9 @@

        boolean wasEnabledOnStartup;
        /** Is auto-update enabled? */
-       boolean isAutoUpdateAllowed;
+       volatile boolean isAutoUpdateAllowed;
        /** Has the user given the go-ahead? */
-       boolean armed;
+       volatile boolean armed;
        /** Should we check for freenet-ext.jar updates? 
         * Normally set only when our freenet-ext.jar is known to be out of 
date. */
        final boolean shouldUpdateExt;
@@ -67,13 +67,13 @@

        final RevocationChecker revocationChecker;
        private String revocationMessage;
-       private boolean hasBeenBlown;
-       private boolean peersSayBlown;
+       private volatile boolean hasBeenBlown;
+       private volatile boolean peersSayBlown;

        /** Is there a new main jar ready to deploy? */
-       private boolean hasNewMainJar;
+       private volatile boolean hasNewMainJar;
        /** Is there a new ext jar ready to deploy? */
-       private boolean hasNewExtJar;
+       private volatile boolean hasNewExtJar;
        /** If another main jar is being fetched, when did the fetch start? */
        private long startedFetchingNextMainJar;
        /** If another ext jar is being fetched, when did the fetch start? */
@@ -201,13 +201,8 @@
        /**
         * Is auto-update enabled?
         */
-       public boolean isEnabled() {
-               NodeUpdater updater;
-               synchronized(this) {
-                       updater = mainUpdater;
-                       if(updater == null) return false;
-               }
-               return updater.isRunning();
+       public synchronized boolean isEnabled() {
+               return (mainUpdater != null);
        }

        /**
@@ -223,7 +218,7 @@
                }
                NodeUpdater main = null, ext = null;
                synchronized(this) {
-                       boolean enabled = (mainUpdater != null && 
mainUpdater.isRunning());
+                       boolean enabled = (mainUpdater != null);
                        if(enabled == enable) return;
                        if(!enable) {
                                // Kill it
@@ -294,9 +289,8 @@
                                updateURI = uri;
                                updater = mainUpdater;
                        }
+                       if(updater == null) return;
                }
-               if(updater == null) return;
-               if(updater.isRunning()) return;
                updater.onChangeURI(uri);
        }

@@ -320,7 +314,7 @@
        /**
         * @return Is auto-update currently enabled?
         */
-       public synchronized boolean isAutoUpdateAllowed() {
+       public boolean isAutoUpdateAllowed() {
                return isAutoUpdateAllowed;
        }

@@ -707,9 +701,7 @@
        }

        public void arm() {
-               synchronized(this) {
-                       armed = true;
-               }
+               armed = true;
                deployOffThread(0);
        }

@@ -734,11 +726,11 @@
                return hasBeenBlown;
        }

-       public synchronized boolean hasNewMainJar() {
+       public boolean hasNewMainJar() {
                return hasNewMainJar;
        }

-       public synchronized boolean hasNewExtJar() {
+       public boolean hasNewExtJar() {
                return hasNewExtJar;
        }


Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2008-07-16 
12:43:00 UTC (rev 21145)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2008-07-16 
13:20:29 UTC (rev 21146)
@@ -88,14 +88,15 @@
                if(!isRunning) return;
                int found = (int)key.suggestedEdition;

-               if(found > availableVersion){
-                       Logger.minor(this, "Updating availableVersion from 
"+availableVersion+" to "+found+" and queueing an update");
+               if(found > availableVersion) {
+                       Logger.minor(this, "Updating availableVersion from " + 
availableVersion + " to " + found + " and queueing an update");
                        this.availableVersion = found;
                        ticker.queueTimedJob(new Runnable() {
+
                                public void run() {
                                        maybeUpdate();
                                }
-                       }, 60*1000); // leave some time in case we get later 
editions
+                       }, 60 * 1000); // leave some time in case we get later 
editions
                        // LOCKING: Always take the NodeUpdater lock *BEFORE* 
the NodeUpdateManager lock
                        manager.onStartFetching(extUpdate);
                }
@@ -267,10 +268,6 @@
        public void onGeneratedURI(FreenetURI uri, BaseClientPutter state) {
                // Impossible
        }
-
-       public synchronized boolean isRunning(){
-               return isRunning;
-       }

        /** Called before kill(). Don't do anything that will involve taking 
locks. */
        public void preKill() {


Reply via email to