When updating a bundle, the global lock is now acquired to check if the bundle
can be auto-refreshed. (FELIX-851)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@746293 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 66141ce..4ce023f 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1629,20 +1629,29 @@
 
                 fireBundleEvent(BundleEvent.UPDATED, bundle);
 
-                // If the bundle is not used by anyone, then garbage
-                // collect it now.
-                if (!bundle.isUsed())
+                // Acquire global lock to check if we should auto-refresh.
+                acquireGlobalLock();
+
+                try
                 {
-                    try
+                    if (!bundle.isUsed())
                     {
-                        refreshPackages(new BundleImpl[] { bundle });
+                        try
+                        {
+                            refreshPackages(new BundleImpl[] { bundle });
+                        }
+                        catch (Exception ex)
+                        {
+                            m_logger.log(
+                                Logger.LOG_ERROR,
+                                "Unable to immediately purge the bundle revisions.", ex);
+                        }
                     }
-                    catch (Exception ex)
-                    {
-                        m_logger.log(
-                            Logger.LOG_ERROR,
-                            "Unable to immediately purge the bundle revisions.", ex);
-                    }
+                }
+                finally
+                {
+                    // Always release the global lock.
+                    releaseGlobalLock();
                 }
             }