felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1424308 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Date Thu, 20 Dec 2012 04:52:43 GMT
Author: djencks
Date: Thu Dec 20 04:52:42 2012
New Revision: 1424308

URL: http://svn.apache.org/viewvc?rev=1424308&view=rev
Log:
use atomic integer to track use count to avoid possible concurrent modifications

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=1424308&r1=1424307&r2=1424308&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Thu Dec 20 04:52:42 2012
@@ -21,6 +21,7 @@ package org.apache.felix.scr.impl.manage
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.config.ComponentHolder;
@@ -54,7 +55,7 @@ public class ImmediateComponentManager<S
     private volatile S m_tmpImplementationObject;
 
     // keep the using bundles as reference "counters" for instance deactivation
-    private volatile int m_useCount;
+    private final AtomicInteger m_useCount = new AtomicInteger( );
 
     // The context that will be passed to the implementationObject
     private ComponentContextImpl m_componentContext;
@@ -164,7 +165,7 @@ public class ImmediateComponentManager<S
         if ( m_implementationObject != null )
         {
             disposeImplementationObject( m_implementationObject, m_componentContext, reason
);
-            m_useCount = 0;
+            m_useCount.set( 0 );
             m_implementationObject = null;
             log( LogService.LOG_DEBUG, "Unset implementation object for component {0} in
deleteComponent for reason {1}", new Object[] { getName(), reason },  null );
             m_componentContext = null;
@@ -712,7 +713,7 @@ public class ImmediateComponentManager<S
                         S result = (S) state().getService( this );
                         if ( result != null )
                         {
-                            m_useCount++;
+                            m_useCount.incrementAndGet();
                         }
                         return result;
                     }
@@ -723,7 +724,7 @@ public class ImmediateComponentManager<S
                     releaseWriteLock( "ImmediateComponentManager.getService.1" );
                 }
             }
-            m_useCount++;
+            m_useCount.incrementAndGet();
             return (S) implementationObject;
     }
 
@@ -731,19 +732,19 @@ public class ImmediateComponentManager<S
     {
         // the framework should not call ungetService more than it calls
         // calls getService. Still, we want to be sure to not go below zero
-        if ( m_useCount > 0 )
+        if ( m_useCount.get() > 0 )
         {
-            m_useCount--;
+            int useCount = m_useCount.decrementAndGet();
 
             // unget the service instance if no bundle is using it
             // any longer unless delayed component instances have to
             // be kept (FELIX-3039)
-            if ( m_useCount == 0 && !isImmediate() && !getActivator().getConfiguration().keepInstances()
)
+            if ( useCount == 0 && !isImmediate() && !getActivator().getConfiguration().keepInstances()
)
             {
                 obtainWriteLock( "ImmediateComponentManager.ungetService.1" );
                 try
                 {
-                    if ( m_useCount == 0 )
+                    if ( m_useCount.get() == 0 )
                     {
                         state().ungetService( this );
                         unsetDependencyMap();



Mime
View raw message