void clear() { if (count != 0) { lock(); try { AtomicReferenceArray<E> table = this.table; for (int i = 0; i < table.length(); ++i) { table.set(i, null); } maybeClearReferenceQueues(); readCount.set(0); ++modCount; count = 0; // write-volatile } finally { unlock(); } } }
void clear() { if (count != 0) { lock(); try { AtomicReferenceArray<E> table = this.table; for (int i = 0; i < table.length(); ++i) { table.set(i, null); } maybeClearReferenceQueues(); readCount.set(0); ++modCount; count = 0; // write-volatile } finally { unlock(); } } }
void runLockedCleanup() { if (tryLock()) { try { maybeDrainReferenceQueues(); readCount.set(0); } finally { unlock(); } } } }
/** Clears a value that has not yet been set, and thus does not require count to be modified. */ @CanIgnoreReturnValue boolean clearValueForTesting( K key, int hash, WeakValueReference<K, V, ? extends InternalEntry<K, V, ?>> valueReference) { lock(); try { AtomicReferenceArray<E> table = this.table; int index = hash & (table.length() - 1); E first = table.get(index); for (E e = first; e != null; e = e.getNext()) { K entryKey = e.getKey(); if (e.getHash() == hash && entryKey != null && map.keyEquivalence.equivalent(key, entryKey)) { WeakValueReference<K, V, E> v = ((WeakValueEntry<K, V, E>) e).getValueReference(); if (v == valueReference) { E newFirst = removeFromChain(first, e); table.set(index, newFirst); return true; } return false; } } return false; } finally { unlock(); } }
/** Removes an entry whose key has been garbage collected. */ @CanIgnoreReturnValue boolean reclaimKey(E entry, int hash) { lock(); try { int newCount = count - 1; AtomicReferenceArray<E> table = this.table; int index = hash & (table.length() - 1); E first = table.get(index); for (E e = first; e != null; e = e.getNext()) { if (e == entry) { ++modCount; E newFirst = removeFromChain(first, e); newCount = this.count - 1; table.set(index, newFirst); this.count = newCount; // write-volatile return true; } } return false; } finally { unlock(); } }
void clear() { if (count != 0) { lock(); try { AtomicReferenceArray<E> table = this.table; for (int i = 0; i < table.length(); ++i) { table.set(i, null); } maybeClearReferenceQueues(); readCount.set(0); ++modCount; count = 0; // write-volatile } finally { unlock(); } } }
/** Cleanup collected entries when the lock is available. */ void tryDrainReferenceQueues() { if (tryLock()) { try { maybeDrainReferenceQueues(); } finally { unlock(); } } }
return null; } finally { unlock();
void runLockedCleanup() { if (tryLock()) { try { maybeDrainReferenceQueues(); readCount.set(0); } finally { unlock(); } } } }
/** Clears a value that has not yet been set, and thus does not require count to be modified. */ @CanIgnoreReturnValue boolean clearValueForTesting( K key, int hash, WeakValueReference<K, V, ? extends InternalEntry<K, V, ?>> valueReference) { lock(); try { AtomicReferenceArray<E> table = this.table; int index = hash & (table.length() - 1); E first = table.get(index); for (E e = first; e != null; e = e.getNext()) { K entryKey = e.getKey(); if (e.getHash() == hash && entryKey != null && map.keyEquivalence.equivalent(key, entryKey)) { WeakValueReference<K, V, E> v = ((WeakValueEntry<K, V, E>) e).getValueReference(); if (v == valueReference) { E newFirst = removeFromChain(first, e); table.set(index, newFirst); return true; } return false; } } return false; } finally { unlock(); } }
/** Cleanup collected entries when the lock is available. */ void tryDrainReferenceQueues() { if (tryLock()) { try { maybeDrainReferenceQueues(); } finally { unlock(); } } }
void runLockedCleanup() { if (tryLock()) { try { maybeDrainReferenceQueues(); readCount.set(0); } finally { unlock(); } } } }
/** Removes an entry whose key has been garbage collected. */ @CanIgnoreReturnValue boolean reclaimKey(E entry, int hash) { lock(); try { int newCount = count - 1; AtomicReferenceArray<E> table = this.table; int index = hash & (table.length() - 1); E first = table.get(index); for (E e = first; e != null; e = e.getNext()) { if (e == entry) { ++modCount; E newFirst = removeFromChain(first, e); newCount = this.count - 1; table.set(index, newFirst); this.count = newCount; // write-volatile return true; } } return false; } finally { unlock(); } }
/** Cleanup collected entries when the lock is available. */ void tryDrainReferenceQueues() { if (tryLock()) { try { maybeDrainReferenceQueues(); } finally { unlock(); } } }