Skip to content

Commit 1318aa8

Browse files
author
alecbarber
committed
Moved localCount to ThreadConfinedReferenceCounter
1 parent 1b78742 commit 1318aa8

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

realm/realm-library/src/main/java/io/realm/RealmCache.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ interface Callback0 {
6868

6969
private abstract static class ReferenceCounter {
7070

71-
// How many references to this Realm instance in this thread.
72-
protected final ThreadLocal<Integer> localCount = new ThreadLocal<>();
7371
// How many threads have instances refer to this configuration.
7472
protected AtomicInteger globalCount = new AtomicInteger(0);
7573

@@ -126,7 +124,6 @@ void onRealmCreated(BaseRealm realm) {
126124
// The Realm instance has been created without exceptions. Cache and reference count can be updated now.
127125
cachedRealm = realm;
128126

129-
localCount.set(0);
130127
// The global count for a frozen Realm has the same role as the local count for a live
131128
// Realm, so initialise it to 0.
132129
globalCount.set(0);
@@ -137,9 +134,7 @@ void onRealmCreated(BaseRealm realm) {
137134
public void clearThreadLocalCache() {
138135
String canonicalPath = cachedRealm.getPath();
139136

140-
// The last instance in this thread.
141-
// Clears local ref & counter.
142-
localCount.set(null);
137+
// The last instance of this frozen Realm. Clear reference.
143138
cachedRealm = null;
144139

145140
// Clears global counter.
@@ -168,6 +163,8 @@ public void setThreadCount(int refCount) {
168163
private static class ThreadConfinedReferenceCounter extends ReferenceCounter {
169164
// The Realm instance in this thread.
170165
private final ThreadLocal<BaseRealm> localRealm = new ThreadLocal<>();
166+
// How many references to this Realm instance in this thread.
167+
protected final ThreadLocal<Integer> localCount = new ThreadLocal<>();
171168

172169
@Override
173170
public boolean hasInstanceAvailableForThread() {

0 commit comments

Comments
 (0)