Skip to content

Commit

Permalink
create FM objects w/ reference count of one
Browse files Browse the repository at this point in the history
patch by jbellis

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1152416 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed Jul 30, 2011
1 parent 6aa406f commit c6741f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/java/org/apache/cassandra/cache/FreeableMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@

public class FreeableMemory extends Memory
{
AtomicInteger references = new AtomicInteger(0);
AtomicInteger references = new AtomicInteger(1);

public FreeableMemory(long size)
{
super(size);
}

/** @return true if we succeed in referencing before the reference count reaches zero */
/**
* @return true if we succeed in referencing before the reference count reaches zero.
* (A FreeableMemory object is created with a reference count of one.)
*/
public boolean reference()
{
while (true)
Expand Down
1 change: 0 additions & 1 deletion src/java/org/apache/cassandra/cache/SerializingCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public void put(K key, V value)
if (mem == null)
return; // out of memory. never mind.

mem.reference();
FreeableMemory old = map.put(key, mem);
if (old != null)
old.unreference();
Expand Down
2 changes: 2 additions & 0 deletions test/unit/org/apache/cassandra/cache/CacheProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class CacheProviderTest extends SchemaLoader
private void simpleCase(ColumnFamily cf, ICache<String, ColumnFamily> cache)
{
cache.put(key1, cf);
assert cache.get(key1) != null;

assertDigests(cache.get(key1), cf);
cache.put(key2, cf);
cache.put(key3, cf);
Expand Down

0 comments on commit c6741f3

Please sign in to comment.