Only mark a bundle as lock after it is verified it is lockable. (FELIX-891)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@736133 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 965ee51..8b4ab48 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -3946,10 +3946,12 @@
     {
         synchronized (m_bundleLock)
         {
-            // Wait if any thread has the global lock, unless the current thread
+            // Wait if the desired bundle is already locked by someone else
+            // or if any thread has the global lock, unless the current thread
             // holds the global lock.
-            while ((m_globalLockCount > 0)
-                && !m_lockingThreadMap.containsKey(Thread.currentThread()))
+            while (!bundle.isLockable() ||
+                ((m_globalLockCount > 0)
+                && !m_lockingThreadMap.containsKey(Thread.currentThread())))
             {
                 try
                 {
@@ -3970,18 +3972,7 @@
             counter[0]++;
             m_lockingThreadMap.put(Thread.currentThread(), counter);
 
-            // Wait until the bundle lock is available, then lock it.
-            while (!bundle.isLockable())
-            {
-                try
-                {
-                    m_bundleLock.wait();
-                }
-                catch (InterruptedException ex)
-                {
-                    // Ignore and just keep waiting.
-                }
-            }
+            // Acquire the bundle lock.
             bundle.lock();
         }
     }