diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-30 14:38:18 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-30 14:54:50 +0100 |
commit | 3cc97ab837ce8bd66627b5f186db8d307c98d902 (patch) | |
tree | e8c949b688e097da2a1dbca0eccb700c25d1eea4 /jdisc_core/src/main/java/com/yahoo/jdisc/refcount | |
parent | 9d4a1d80b09d58a6a91257e45afdf6bb3315a7d3 (diff) |
- Storing references instead of just counting them has been default for a while now, so making it default in code too.
- Remove option to do just do refcounting.
Diffstat (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/refcount')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java b/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java deleted file mode 100644 index 0f417c81a8b..00000000000 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.jdisc.refcount; - -import com.yahoo.jdisc.ResourceReference; -import com.yahoo.jdisc.SharedResource; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Does reference counting by using atomic counting of references - * Default in production - * - * @author baldersheim - */ -public class ReferencesByCount implements References { - private final AtomicInteger refCount; - private final DestructableResource resource; - private final NoDebugResourceReference initialReference; - - public ReferencesByCount(DestructableResource resource) { - refCount = new AtomicInteger(1); - this.resource = resource; - initialReference = new NoDebugResourceReference(this); - } - - @Override - public void release() { - initialReference.close(); - } - - @Override - public int referenceCount() { - return refCount.get(); - } - - @Override - public ResourceReference refer(Object context) { - addRef(1); - return new NoDebugResourceReference(this); - } - - @Override - public String currentState() { - return "Active references: " + refCount.get() + "." - + " Resource reference debugging is turned off. Consider toggling the " - + SharedResource.SYSTEM_PROPERTY_NAME_DEBUG - + " system property to get debugging assistance with reference tracking."; - } - - private void removeRef() { - int refCount = addRef(-1); - if (refCount == 0) { - resource.close(); - } - } - - private int addRef(int value) { - while (true) { - int prev = refCount.get(); - if (prev == 0) { - throw new IllegalStateException(getClass().getName() + ".addRef(" + value + "):" - + " Object is already destroyed." - + " Consider toggling the " + SharedResource.SYSTEM_PROPERTY_NAME_DEBUG - + " system property to get debugging assistance with reference tracking."); - } - int next = prev + value; - if (refCount.compareAndSet(prev, next)) { - return next; - } - } - } - - private static class NoDebugResourceReference extends CloseableOnce { - private final ReferencesByCount resource; - - NoDebugResourceReference(final ReferencesByCount resource) { - this.resource = resource; - } - - @Override final void onClose() { resource.removeRef(); } - @Override References getReferences() { return resource; } - } -} |