A couple of fixes to prevent deadlocks where we were calling out to the framework whilst holding a lock. This seems to fix some issues in FELIX-3337 (which was failing on trunk, even though it had been resolved before) and hopefully prevents some deadlocks for which we currently have no tests.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1345927 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
index 23de8fd..04e13a5 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
@@ -381,9 +381,15 @@
         calculateStateChanges(oldState, newState);
     }
 
-    public synchronized void start() {
-    	if (!m_isStarted) {
-    	    m_isStarted = true;
+    public void start() {
+        boolean needsStarting = false;
+        synchronized (this) {
+            if (!m_isStarted) {
+                m_isStarted = true;
+                needsStarting = true;
+            }
+        }
+        if (needsStarting) {
 	        State oldState, newState;
 	        synchronized (m_dependencies) {
 	            oldState = m_state;
@@ -394,9 +400,15 @@
     	}
     }
 
-    public synchronized void stop() {
-        if (m_isStarted) {
-            m_isStarted = false;
+    public void stop() {
+        boolean needsStopping = false;
+        synchronized (this) {
+            if (m_isStarted) {
+                m_isStarted = false;
+                needsStopping = true;
+            }
+        }
+        if (needsStopping) {
 	        State oldState, newState;
 	        synchronized (m_dependencies) {
 	            oldState = m_state;
@@ -479,10 +491,18 @@
 	    return null;
 	}
 
-	public synchronized Component setServiceProperties(Dictionary serviceProperties) {
-	    m_serviceProperties = serviceProperties;
-	    if ((m_registration != null) && (m_serviceName != null)) {
-	        m_registration.setProperties(calculateServiceProperties());
+	public Component setServiceProperties(Dictionary serviceProperties) {
+	    boolean needsProperties = false;
+	    Dictionary properties = null;
+	    synchronized (this) {
+	        m_serviceProperties = serviceProperties;
+	        if ((m_registration != null) && (m_serviceName != null)) {
+	            properties = calculateServiceProperties();
+	            needsProperties = true;
+	        }
+	    }
+	    if (needsProperties) {
+	        m_registration.setProperties(properties);
 	    }
 	    return this;
 	}
@@ -899,9 +919,9 @@
     private void updateInstance(Dependency dependency) {
         if (dependency.isAutoConfig()) {
             configureImplementation(dependency.getAutoConfigType(), dependency.getAutoConfigInstance(), dependency.getAutoConfigName());
-            if (dependency.isPropagated() && m_registration != null) {
-                m_registration.setProperties(calculateServiceProperties());
-            }
+        }
+        if (dependency.isPropagated() && m_registration != null) {
+            m_registration.setProperties(calculateServiceProperties());
         }
     }