You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2015/07/31 16:28:22 UTC
svn commit: r1693609 - in /felix/trunk/framework/src:
main/java/org/apache/felix/framework/ServiceRegistry.java
test/java/org/apache/felix/framework/ServiceRegistryTest.java
Author: davidb
Date: Fri Jul 31 14:28:21 2015
New Revision: 1693609
URL: http://svn.apache.org/r1693609
Log:
FELIX-4977 Service Registry Concurrency - add extra check before ungetService()
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
felix/trunk/framework/src/test/java/org/apache/felix/framework/ServiceRegistryTest.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=1693609&r1=1693608&r2=1693609&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:28:21 2015
@@ -452,12 +452,17 @@ public class ServiceRegistry
if (svc != null)
{
- if (usage.m_svcHolderRef.compareAndSet(holder, null))
+ // Check the count again to ensure that nobody else has just
+ // obtained the service again
+ if (usage.m_count.get() <= 0)
{
- // Remove reference from usages array.
- ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
- .getRegistration().ungetService(bundle, svc);
+ if (usage.m_svcHolderRef.compareAndSet(holder, null))
+ {
+ // Remove reference from usages array.
+ ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
+ .getRegistration().ungetService(bundle, svc);
+ }
}
}
}
Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/ServiceRegistryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/ServiceRegistryTest.java?rev=1693609&r1=1693608&r2=1693609&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/ServiceRegistryTest.java (original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/ServiceRegistryTest.java Fri Jul 31 14:28:21 2015
@@ -1053,14 +1053,12 @@ public class ServiceRegistryTest extends
final class ObserverImpl implements Observer
{
-// private volatile int counter = 0;
private final AtomicInteger counter = new AtomicInteger();
public volatile boolean active = true;
@Override
public void update(Observable o, Object arg)
{
-// counter++; // Not completely atomic, but that doesn't matter here.
counter.incrementAndGet();
if ( !active )
{