Refine search
private ConcurrentHashMap<TimerKey, BaseAction[]> getExecutorOrCreate(int seconds) { ConcurrentHashMap<TimerKey, BaseAction[]> secondExecutor = timerExecutors.get(seconds); if (secondExecutor != null) { return secondExecutor; } ConcurrentHashMap<TimerKey, BaseAction[]> newSecondExecutorMap = new ConcurrentHashMap<>(); if (timerExecutors.compareAndSet(seconds, null, newSecondExecutorMap)) { return newSecondExecutorMap; } return timerExecutors.get(seconds); }
/** * Gets the formatter for the specified style. * * @param dateStyle the date style * @param timeStyle the time style * @return the formatter */ private static DateTimeFormatter createFormatterForStyleIndex(int dateStyle, int timeStyle) { int index = ((dateStyle << 2) + dateStyle) + timeStyle; // (dateStyle * 5 + timeStyle); // Should never happen but do a double check... if (index >= cStyleCache.length()) { return createDateTimeFormatter(dateStyle, timeStyle); } DateTimeFormatter f = cStyleCache.get(index); if (f == null) { f = createDateTimeFormatter(dateStyle, timeStyle); if (cStyleCache.compareAndSet(index, null, f) == false) { f = cStyleCache.get(index); } } return f; }
/** * Frees the object. If the free list is full, the object will be garbage * collected. * * @param obj the object to be freed. */ public boolean free(T obj) { int top = _top.get(); if (top < _freeStack.length()) { boolean isFree = _freeStack.compareAndSet(top, null, obj); _top.compareAndSet(top, top + 1); return isFree; } else { return false; } }
/** * Gets the formatter for the specified style. * * @param dateStyle the date style * @param timeStyle the time style * @return the formatter */ private static DateTimeFormatter createFormatterForStyleIndex(int dateStyle, int timeStyle) { int index = ((dateStyle << 2) + dateStyle) + timeStyle; // (dateStyle * 5 + timeStyle); // Should never happen but do a double check... if (index >= cStyleCache.length()) { return createDateTimeFormatter(dateStyle, timeStyle); } DateTimeFormatter f = cStyleCache.get(index); if (f == null) { f = createDateTimeFormatter(dateStyle, timeStyle); if (cStyleCache.compareAndSet(index, null, f) == false) { f = cStyleCache.get(index); } } return f; }
/** * Get or create a trace object for this module id. Trace modules with id * are cached. * * @param moduleId module id * @return the trace object */ public Trace getTrace(int moduleId) { Trace t = traces.get(moduleId); if (t == null) { t = new Trace(writer, moduleId); if (!traces.compareAndSet(moduleId, null, t)) { t = traces.get(moduleId); } } return t; }
/** * Frees the object. If the free list is full, the object will be garbage * collected. * * @param obj the object to be freed. */ public boolean free(T obj) { int top = _top.get(); if (top < _freeStack.length()) { boolean isFree = _freeStack.compareAndSet(top, null, obj); _top.compareAndSet(top, top + 1); return isFree; } else { return false; } }
/** * Gets the formatter for the specified style. * * @param dateStyle the date style * @param timeStyle the time style * @return the formatter */ private static DateTimeFormatter createFormatterForStyleIndex(int dateStyle, int timeStyle) { int index = ((dateStyle << 2) + dateStyle) + timeStyle; // (dateStyle * 5 + timeStyle); // Should never happen but do a double check... if (index >= cStyleCache.length()) { return createDateTimeFormatter(dateStyle, timeStyle); } DateTimeFormatter f = cStyleCache.get(index); if (f == null) { f = createDateTimeFormatter(dateStyle, timeStyle); if (cStyleCache.compareAndSet(index, null, f) == false) { f = cStyleCache.get(index); } } return f; }
/** * Get or create a trace object for this module id. Trace modules with id * are cached. * * @param moduleId module id * @return the trace object */ public Trace getTrace(int moduleId) { Trace t = traces.get(moduleId); if (t == null) { t = new Trace(writer, moduleId); if (!traces.compareAndSet(moduleId, null, t)) { t = traces.get(moduleId); } } return t; }
/** * Frees the object. If the free list is full, the object will be garbage * collected. * * @param obj the object to be freed. */ public boolean free(T obj) { int top = _top.get(); if (top < _freeStack.length()) { boolean isFree = _freeStack.compareAndSet(top, null, obj); _top.compareAndSet(top, top + 1); return isFree; } else { return false; } }
for (int j = 0; j < src.length() - 1; ) Object o = src.get(j); if (o == null) if (src.compareAndSet(j, null, RESIZED)) if (src.compareAndSet(j, o, RESIZING))
/** * @param val value to box to native long. * @return native long. */ @NotNull private static NativeLong nl(long val) { if (val % NL_CACHE_DIVISOR == 0 && val < CACHED_LONGS * NL_CACHE_DIVISOR) { int cacheIdx = (int)(val / NL_CACHE_DIVISOR); NativeLong curCached = nativeLongCache.get(cacheIdx); if (curCached != null) return curCached; NativeLong nl = new NativeLong(val); nativeLongCache.compareAndSet(cacheIdx, null, nl); return nl; } return new NativeLong(val); }
/** * Frees the object. If the free list is full, the object will be garbage * collected. * * @param obj the object to be freed. */ public boolean free(T obj) { int top = _top.get(); if (top < _freeStack.length()) { boolean isFree = _freeStack.compareAndSet(top, null, obj); _top.compareAndSet(top, top + 1); return isFree; } else return false; } public boolean allowFree(T obj) {
public V put(K key, V value) { int hash = this.hash(key); AtomicReferenceArray currentArray = this.table; int length = currentArray.length(); int index = ConcurrentHashMap.indexFor(hash, length); Object o = currentArray.get(index); if (o == null) { Entry<K, V> newEntry = new Entry<K, V>(key, value, null); if (currentArray.compareAndSet(index, null, newEntry)) { this.addToSize(1); return null; } } return this.slowPut(key, value, hash, currentArray); }
DefaultAttribute<?> head = attributes.get(i); if (head == null) { head.next = attr; attr.prev = head; if (attributes.compareAndSet(i, null, head)) { head = attributes.get(i);
for (int j = 0; j < src.length() - 1; ) Object o = src.get(j); if (o == null) if (src.compareAndSet(j, null, RESIZED)) if (src.compareAndSet(j, o, RESIZING))
@Override public L getAt(int index) { if (size != Integer.MAX_VALUE) { Preconditions.checkElementIndex(index, size()); } // else no check necessary, all index values are valid ArrayReference<? extends L> existingRef = locks.get(index); L existing = existingRef == null ? null : existingRef.get(); if (existing != null) { return existing; } L created = supplier.get(); ArrayReference<L> newRef = new ArrayReference<L>(created, index, queue); while (!locks.compareAndSet(index, existingRef, newRef)) { // we raced, we need to re-read and try again existingRef = locks.get(index); existing = existingRef == null ? null : existingRef.get(); if (existing != null) { return existing; } } drainQueue(); return created; }
private boolean doReplace(final V oldValue, final V newValue, final Table<V> table) { final int key = indexer.applyAsInt(oldValue); final AtomicReferenceArray<V[]> array = table.array; final int idx = key & array.length() - 1; OUTER: for (;;) { // Fetch the table row. V[] oldRow = array.get(idx); if (oldRow == null) { // no match for the key return false; } if (oldRow == RESIZED) { return doReplace(oldValue, newValue, table.resizeView); } for (int i = 0, length = oldRow.length; i < length; i++) { final V tryItem = oldRow[i]; if (ve.equals(tryItem, oldValue)) { final V[] newRow = oldRow.clone(); newRow[i] = newValue; if (array.compareAndSet(i, oldRow, newRow)) { return true; } else { continue OUTER; } } } return false; } }
DefaultAttribute<?> head = attributes.get(i); if (head == null) { head.next = attr; attr.prev = head; if (attributes.compareAndSet(i, null, head)) { head = attributes.get(i);
for (int j = 0; j < src.length() - 1; ) Object o = src.get(j); if (o == null) if (src.compareAndSet(j, null, RESIZED)) if (src.compareAndSet(j, o, RESIZING))
private void basicFree(long addr, int idx, AtomicReferenceArray<OffHeapStoredObjectAddressStack> freeLists) { OffHeapStoredObjectAddressStack clq = freeLists.get(idx); if (clq != null) { clq.offer(addr); } else { clq = createFreeListForEmptySlot(freeLists, idx); clq.offer(addr); if (!freeLists.compareAndSet(idx, null, clq)) { clq = freeLists.get(idx); clq.offer(addr); } } }