felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1693602 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
Date Fri, 31 Jul 2015 14:07:42 GMT
Author: davidb
Date: Fri Jul 31 14:07:42 2015
New Revision: 1693602

URL: http://svn.apache.org/r1693602
Log:
FELIX-4977 Concurrency issues with Service Registry.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1693602&r1=1693601&r2=1693602&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java Fri
Jul 31 14:07:42 2015
@@ -380,6 +380,8 @@ public class ServiceRegistry
     }
 
     // Increment the Atomic Long by 1, and ensure the result is at least 1.
+    // This method uses a loop, optimistic algorithm to do this in a threadsafe
+    // way without locks.
     private void incrementToPositiveValue(AtomicLong al)
     {
         boolean success = false;
@@ -469,9 +471,11 @@ public class ServiceRegistry
                     usage.m_svcHolderRef.set(null);
                 }
 
-                // If the registration is invalid or the usage count has reached
-                // zero, then flush it.
-                if (!reg.isValid())
+                // If the registration is invalid or the usage count for a prototype
+                // reached zero, then flush it. Non-prototype services are not flushed
+                // on ungetService() when they reach 0 as this introduces a race
+                // condition of concurrently the same service is obtained via getService()
+                if (!reg.isValid() || (count <= 0 && svcObj != null))
                 {
                     flushUsageCount(bundle, ref, usage);
                 }



Mime
View raw message