protected Cons<GarbageCollectable> writeBackLoop(int newTxNumber, int min, int max, VBox[] vboxes, Object[] values) { Cons<GarbageCollectable> newBodies = Cons.empty(); for (int i = max - 1; i >= min; i--) { VBox vbox = vboxes[i]; Object newValue = values[i]; VBoxBody newBody = vbox.commit((newValue == ReadWriteTransaction.NULL_VALUE) ? null : newValue, newTxNumber); newBodies = newBodies.cons(newBody); } return newBodies; }
private E removeExisting(Cons<E> frontElems) { E result = frontElems.first(); frontElems = frontElems.rest(); if (frontElems.isEmpty()) { frontElems = rear.get().reverse(); if (!frontElems.isEmpty()) { // only clear the rear if it had anything rear.put((Cons<E>) Cons.empty()); } } front.put(frontElems); size.dec(); return result; }
protected WriteSet(Cons<VBox> vboxesWrittenBack) { int writeSetLength = vboxesWrittenBack.size(); int nBlocks = 1; int blockSize = writeSetLength; VBox[] vboxes = new VBox[writeSetLength]; Object[] values = new Object[writeSetLength]; Cons<GarbageCollectable>[] bodiesPerBlock = new Cons[nBlocks]; AtomicBoolean[] blocksDone = new AtomicBoolean[nBlocks]; int pos = 0; Cons<GarbageCollectable> bodiesCommitted = Cons.empty(); for (VBox vbox : vboxesWrittenBack) { vboxes[pos] = vbox; values[pos++] = vbox.body.value; bodiesCommitted = bodiesCommitted.cons(vbox.body); } bodiesPerBlock[0] = bodiesCommitted; blocksDone[0] = new AtomicBoolean(true); this.normalWriteSet = new BoxesToCommit(nBlocks, blockSize, vboxes, values, writeSetLength, bodiesPerBlock, blocksDone); this.arrayCommitState = new VArrayCommitState[0]; }
private final Cons<E> removeExistingCons(Cons<?> cons) { if (cons == this) { return rest; } else { // We have to allocate new Cons cells until we reach the cons to remove Cons<E> newCons = ((Cons<E>)EMPTY).cons(first); Cons<E> next = rest; while (next != cons) { newCons = newCons.cons(next.first); next = next.rest; } // share the rest newCons = newCons.reverseInto(next.rest); return newCons; } }
private void findLeftmost(RedBlackTree<T> node) { while (node.left != EMPTY) { path = path.cons(node); node = node.left; } this.next = node; }
public NestedCommitRecord() { this.committer = null; this.childrenToPropagate = Cons.empty(); this.expectedParentOrecs = Cons.empty(); this.varrayReadsToPropagate = Cons.empty(); this.arrayWritesToPropagate = ReadWriteTransaction.EMPTY_MAP; this.arrayWritesCount = ReadWriteTransaction.EMPTY_MAP; this.commitNumber = 0; this.recordCommitted = true; }
protected Iterator<DependenceRecord> getDependenceRecordsToRecheck() { Cons<Iterator<DependenceRecord>> iteratorsList = Cons.empty(); for (VBox box : boxesWritten.keySet()) { Depended dep = DependedVBoxes.getDependedForBoxIfExists(box); if (dep != null) { iteratorsList = iteratorsList.cons(dep.getDependenceRecords().iterator()); } } return new ChainedIterator<DependenceRecord>(iteratorsList.iterator()); }
@Override @Atomic(canFail = false) public boolean retainAll(Collection<?> c) { Cons<E> result = Cons.empty(); Cons<E> elems = entries.get(); int removed = 0; for (E o : elems) { if (c.contains(o)) { result = result.cons(o); } else { removed++; } } if (removed > 0) { entries.put(result.reverse()); size.dec(removed); } return removed > 0; }
@Override protected void deleteDomainObject() { super.deleteDomainObject(); // Mark the VState as deleted obj$state.markAsDeleted(); // Ensure that all RelationLists exist... create$allLists(); Cons<Pair<String, RelationList>> lists = relationLists; while (lists != (Object) Cons.empty()) { // ... and mark them as deleted lists.first().second.markAsDeleted(); lists = lists.rest(); } } }
@Override protected void tryCommit() { ReadWriteTransaction parent = getRWParent(); Cons<ParallelNestedTransaction> currentOrecs; Cons<ParallelNestedTransaction> modifiedOrecs; do { currentOrecs = parent.mergedTxs; modifiedOrecs = currentOrecs.cons(this); for (ParallelNestedTransaction child : mergedTxs) { modifiedOrecs = modifiedOrecs.cons(child); } } while (!parent.CASmergedTxs(currentOrecs, modifiedOrecs)); if (!this.arraysRead.isEmpty()) { synchronized (parent) { parent.arraysRead = this.arraysRead.reverseInto(parent.arraysRead); } } }
private void consolidateElements() { VBox<FunctionalSet<E2>> box = getElementsBox(); FunctionalSet<E2> origSet = box.get(listHolder, attributeName); FunctionalSet<E2> newSet = origSet; if (elementsToRemove.get().size() > 0) { Iterator<E2> iter = elementsToRemove.get().iterator(); while (iter.hasNext()) { newSet = newSet.remove(iter.next()); } elementsToRemove.put(Cons.<E2> empty()); } if (elementsToAdd.get().size() > 0) { Iterator<E2> iter = elementsToAdd.get().iterator(); while (iter.hasNext()) { newSet = newSet.add(iter.next()); } elementsToAdd.put(Cons.<E2> empty()); } if (newSet != origSet) { // Because a nested FenixConsistencyCheckTransaction cannot perform writes, but may need to // consolidate the elements of a relation changed by the parent transaction box.putInParent(newSet); } }
@Override public boolean isWriteTransaction() { Cons<ParallelNestedTransaction> emptyCons = Cons.<ParallelNestedTransaction> empty(); return (mergedTxs != emptyCons) || (!boxesWritten.isEmpty()) || (!boxesWrittenInPlace.isEmpty()) || (!arrayWrites.isEmpty()) || (perTxValues != null && !perTxValues.isEmpty()); }
public final Cons<E> removeAll(Object elem) { Cons<E> lastFound = lastMember(elem); if (lastFound == null) { return this; Cons<E> newCons = ((Cons<E>)EMPTY).cons(next.first); next = next.rest; while (next != lastFound) { if (next.first != null) { newCons = newCons.cons(next.first); while (next != lastFound) { if (! elem.equals(next.first)) { newCons = newCons.cons(next.first); newCons = newCons.reverseInto(next.rest); return newCons;
@Override public boolean justRemove(E2 obj) { TransactionSupport.logAttrChange(listHolder, attributeName); elementsToRemove.put(elementsToRemove.get().cons(obj)); elementsToAdd.put(elementsToAdd.get().removeAll(obj)); // HACK!!! This is to be fixed upon migration to RelationAwareSet // I wouldn't like to force a load of the list to be able to return the correct boolean value return true; }