From c502170924607a8c5ba1edd87a0af22d6b086ec9 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Wed, 20 May 2015 16:01:11 +0200 Subject: [PATCH] removed unused pipes; removed obsolete files; set PipeFactoryRegistry deprecated --- .../framework/pipe/CommittablePipe.java | 65 ---- .../pipe/CommittablePipeFactory.java | 50 --- .../ConcurrentBlockingIntraThreadPipe.java | 53 --- ...currentBlockingIntraThreadPipeFactory.java | 50 --- .../pipe/OrderedGrowableArrayPipe.java | 65 ---- .../pipe/OrderedGrowableArrayPipeFactory.java | 50 --- .../framework/pipe/OrderedGrowablePipe.java | 59 ---- .../framework/pipe/PipeFactoryLoader.java | 2 +- .../framework/pipe/PipeFactoryRegistry.java | 2 + .../framework/pipe/SpScIntraThreadPipe.java | 63 ---- .../pipe/SpScIntraThreadPipeFactory.java | 50 --- .../framework/pipe/UnorderedGrowablePipe.java | 88 ----- .../pipe/UnorderedGrowablePipeFactory.java | 50 --- .../java/teetime/util/HashMapWithDefault.java | 54 ---- .../hashmap/ConcurrentHashMapWithDefault.java | 50 --- .../util/concurrent/hashmap/ValueFactory.java | 31 -- .../workstealing/CircularArray.java | 87 ----- .../workstealing/CircularIntArray.java | 87 ----- .../workstealing/CircularModIntArray.java | 88 ----- .../CircularWorkStealingDeque.java | 305 ------------------ ...CircularWorkStealingDequeWithSentinel.java | 201 ------------ ...kStealingDequeWithThreadLocalSentinel.java | 225 ------------- .../ExceptionalCircularWorkStealingDeque.java | 187 ----------- .../UntypedCircularWorkStealingDeque.java | 181 ----------- ...dExceptionalCircularWorkStealingDeque.java | 189 ----------- .../exception/DequeIsEmptyException.java | 20 -- .../exception/DequePopException.java | 23 -- .../exception/OperationAbortedException.java | 20 -- src/main/resources/pipe-factories.conf | 4 +- 29 files changed, 4 insertions(+), 2395 deletions(-) delete mode 100644 src/main/java/teetime/framework/pipe/CommittablePipe.java delete mode 100644 src/main/java/teetime/framework/pipe/CommittablePipeFactory.java delete mode 100644 src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipe.java delete mode 100644 src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipeFactory.java delete mode 100644 src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java delete mode 100644 src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java delete mode 100644 src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java delete mode 100644 src/main/java/teetime/framework/pipe/SpScIntraThreadPipe.java delete mode 100644 src/main/java/teetime/framework/pipe/SpScIntraThreadPipeFactory.java delete mode 100644 src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java delete mode 100644 src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java delete mode 100644 src/main/java/teetime/util/HashMapWithDefault.java delete mode 100644 src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java delete mode 100644 src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/CircularArray.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java delete mode 100644 src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java diff --git a/src/main/java/teetime/framework/pipe/CommittablePipe.java b/src/main/java/teetime/framework/pipe/CommittablePipe.java deleted file mode 100644 index 09ba2627..00000000 --- a/src/main/java/teetime/framework/pipe/CommittablePipe.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.util.list.CommittableResizableArrayQueue; - -final class CommittablePipe extends AbstractIntraThreadPipe { - - private final CommittableResizableArrayQueue<Object> elements = new CommittableResizableArrayQueue<Object>(null, 4); - - <T> CommittablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - final IPipe pipe = new CommittablePipe(null, null); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - this.elements.addToTailUncommitted(element); - this.elements.commit(); - return true; - } - - @Override - public Object removeLast() { - final Object element = this.elements.removeFromHeadUncommitted(); - this.elements.commit(); - return element; - } - - @Override - public boolean isEmpty() { - return this.elements.isEmpty(); - } - - public CommittableResizableArrayQueue<?> getElements() { - return this.elements; - } - - @Override - public int size() { - return this.elements.size(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java b/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java deleted file mode 100644 index 8589642d..00000000 --- a/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public final class CommittablePipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return this.create(sourcePort, targetPort, 1); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new CommittablePipe(sourcePort, targetPort); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.STACK_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipe.java b/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipe.java deleted file mode 100644 index 5df2677f..00000000 --- a/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipe.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import java.util.concurrent.ConcurrentLinkedQueue; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -final class ConcurrentBlockingIntraThreadPipe<T> extends AbstractIntraThreadPipe { - - private final ConcurrentLinkedQueue<Object> queue; - - ConcurrentBlockingIntraThreadPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - queue = new ConcurrentLinkedQueue<Object>(); - } - - @Override - public boolean add(final Object element) { - return queue.add(element); - } - - @Override - public boolean isEmpty() { - return queue.isEmpty(); - } - - @Override - public int size() { - return queue.size(); - } - - @Override - public Object removeLast() { - return queue.poll(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipeFactory.java b/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipeFactory.java deleted file mode 100644 index f62aee8e..00000000 --- a/src/main/java/teetime/framework/pipe/ConcurrentBlockingIntraThreadPipeFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public final class ConcurrentBlockingIntraThreadPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return this.create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new ConcurrentBlockingIntraThreadPipe<T>(sourcePort, targetPort); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.QUEUE_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java deleted file mode 100644 index db2c09c2..00000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.util.concurrent.workstealing.CircularArray; - -final class OrderedGrowableArrayPipe extends AbstractIntraThreadPipe { - - private final CircularArray<Object> elements; - private int head; - private int tail; - - <T> OrderedGrowableArrayPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new CircularArray<Object>(capacity); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - final IPipe pipe = new OrderedGrowableArrayPipe(sourcePort, targetPort, 4); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - this.elements.put(this.tail++, element); - return true; - } - - @Override - public Object removeLast() { - if (this.head < this.tail) { - return this.elements.get(this.head++); - } else { - return null; - } - } - - @Override - public boolean isEmpty() { - return this.size() == 0; - } - - @Override - public int size() { - return this.tail - this.head; - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java deleted file mode 100644 index d37082fb..00000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public final class OrderedGrowableArrayPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return this.create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new OrderedGrowableArrayPipe(sourcePort, targetPort, capacity); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.QUEUE_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java b/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java deleted file mode 100644 index c51d67ec..00000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import java.util.LinkedList; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -class OrderedGrowablePipe extends AbstractIntraThreadPipe { - - private final LinkedList<Object> elements; - - <T> OrderedGrowablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new LinkedList<Object>(); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - final IPipe pipe = new OrderedGrowablePipe(null, null, 100000); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - return this.elements.offer(element); - } - - @Override - public Object removeLast() { - return this.elements.poll(); - } - - @Override - public boolean isEmpty() { - return this.elements.isEmpty(); - } - - @Override - public int size() { - return this.elements.size(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java index b2673d4d..bfd04189 100644 --- a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java +++ b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import teetime.util.classpath.FileSearcher; -public final class PipeFactoryLoader { +final class PipeFactoryLoader { private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryLoader.class); diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java b/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java index 1f5291c5..2b3a024a 100644 --- a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java +++ b/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java @@ -28,7 +28,9 @@ import org.slf4j.LoggerFactory; * <p> * To get a PipeFactory instance, call {@link #getPipeFactory(ThreadCommunication, PipeOrdering, boolean)}. * + * @Deprecated since 1.2 */ +@Deprecated public final class PipeFactoryRegistry { private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryRegistry.class); diff --git a/src/main/java/teetime/framework/pipe/SpScIntraThreadPipe.java b/src/main/java/teetime/framework/pipe/SpScIntraThreadPipe.java deleted file mode 100644 index bae82ce7..00000000 --- a/src/main/java/teetime/framework/pipe/SpScIntraThreadPipe.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import java.util.Queue; - -import org.jctools.queues.QueueFactory; -import org.jctools.queues.spec.ConcurrentQueueSpec; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -/** - * Represents a less efficient implementation of an intra-thread pipe. - * - * @author Christian Wulf - * - * @param <T> - */ -final class SpScIntraThreadPipe<T> extends AbstractIntraThreadPipe { - - private final Queue<Object> queue; - - SpScIntraThreadPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - queue = QueueFactory.newQueue(ConcurrentQueueSpec.createBoundedSpsc(1)); - } - - @Override - public boolean add(final Object element) { - return queue.offer(element); - } - - @Override - public boolean isEmpty() { - return queue.isEmpty(); - } - - @Override - public int size() { - return queue.size(); - } - - @Override - public Object removeLast() { - return queue.poll(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/SpScIntraThreadPipeFactory.java b/src/main/java/teetime/framework/pipe/SpScIntraThreadPipeFactory.java deleted file mode 100644 index 0fae0a68..00000000 --- a/src/main/java/teetime/framework/pipe/SpScIntraThreadPipeFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public final class SpScIntraThreadPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return this.create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new SpScIntraThreadPipe<T>(sourcePort, targetPort); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.QUEUE_BASED; - } - - @Override - public boolean isGrowable() { - return false; - } - -} diff --git a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java deleted file mode 100644 index e9ef0e96..00000000 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.AbstractIntraThreadPipe; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -final class UnorderedGrowablePipe extends AbstractIntraThreadPipe { - - private Object[] elements; - // private final ArrayWrapper2<T> elements = new ArrayWrapper2<T>(2); - private int lastFreeIndex; - - <T> UnorderedGrowablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new Object[capacity]; - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - final IPipe pipe = new UnorderedGrowablePipe(null, null, 4); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - if (this.lastFreeIndex == this.elements.length) { - // if (this.lastFreeIndex == this.elements.getCapacity()) { - this.elements = this.grow(); - } - this.elements[this.lastFreeIndex++] = element; - // this.elements.put(this.lastFreeIndex++, element); - return true; - } - - @Override - public Object removeLast() { - final Object element = this.elements[--this.lastFreeIndex]; - this.elements[this.lastFreeIndex] = null; - // T element = this.elements.get(--this.lastFreeIndex); - return element; - } - - @Override - public boolean isEmpty() { - return this.lastFreeIndex == 0; - } - - @Override - public int size() { - return this.lastFreeIndex; - } - - private Object[] grow() { - final int newSize = this.elements.length * 2; - // System.out.println("growing to " + newSize); - return this.newArray(newSize); - } - - // we do not support shrink since it causes too much overhead due to the capacity checks - // private T[] shrink() { - // int newSize = this.elements.length / 2; - // return this.newArray(newSize); - // } - - private Object[] newArray(final int newSize) { - final Object[] newElements = new Object[newSize]; - - System.arraycopy(this.elements, 0, newElements, 0, this.elements.length); - - return newElements; - } - -} diff --git a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java deleted file mode 100644 index f1e314e7..00000000 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public final class UnorderedGrowablePipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return this.create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new UnorderedGrowablePipe(sourcePort, targetPort, capacity); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.STACK_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/util/HashMapWithDefault.java b/src/main/java/teetime/util/HashMapWithDefault.java deleted file mode 100644 index a54a1b81..00000000 --- a/src/main/java/teetime/util/HashMapWithDefault.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util; - -import java.util.HashMap; - -import teetime.util.concurrent.hashmap.ValueFactory; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public final class HashMapWithDefault<K, V> extends HashMap<K, V> { - - private static final long serialVersionUID = -7958038532219740472L; - - private final ValueFactory<V> valueFactory; - - /** - * @since 1.10 - */ - public HashMapWithDefault(final ValueFactory<V> valueFactory) { - this.valueFactory = valueFactory; - } - - /** - * @return the corresponding value if the key exists. Otherwise, it creates, - * inserts, and returns a new default value. - */ - @SuppressWarnings("unchecked") - @Override - public V get(final Object key) { - V value = super.get(key); - if (value == null) { - value = this.valueFactory.create(); - super.put((K) key, value); - } - return value; - } -} diff --git a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java b/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java deleted file mode 100644 index 98bdf027..00000000 --- a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.hashmap; - -import java.util.concurrent.ConcurrentHashMap; - -public final class ConcurrentHashMapWithDefault<K, V> extends ConcurrentHashMap<K, V> { - - private static final long serialVersionUID = 199185976241037967L; - - private final ValueFactory<V> valueFactory; - - private int maxElements; - - public ConcurrentHashMapWithDefault(final ValueFactory<V> valueFactory) { - this.valueFactory = valueFactory; - } - - public V getOrCreate(final K key) { - V value = this.get(key); - if (value == null) { - synchronized (this) { - value = this.get(key); - if (value == null) { // NOCS (DCL) - value = this.valueFactory.create(); - this.put(key, value); - this.maxElements++; - } - } - } - return value; - } - - public int getMaxElements() { - return this.maxElements; - } -} diff --git a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java b/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java deleted file mode 100644 index 543cf595..00000000 --- a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.hashmap; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public interface ValueFactory<T> { - - /** - * Create a new instance of the type <code>T</code>. - * - * @since 1.10 - */ - public T create(); -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularArray.java deleted file mode 100644 index 7f1e10a5..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularArray.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularArray<T> { - - private final long logSize; - private final T[] segment; - private final long mask; - private long currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularArray(final long logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.mask = this.getCapacity() - 1; // mask = 0..01..1 - } - - public long getCapacity() { - return this.segment.length; - } - - public T get(final long i) { - return this.segment[(int) (i & this.mask)]; // risk of overflow - } - - public T getNext() { - long index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) & this.mask; - return this.segment[(int) index]; - } - - public void put(final long i, final T o) { - this.segment[(int) (i & this.mask)] = o; // risk of overflow - } - - public CircularArray<T> grow(final long b, final long t) { - final CircularArray<T> a = new CircularArray<T>(this.logSize + 1); - for (long i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularArray<T> shrink(final long b, final long t) { - final CircularArray<T> a = new CircularArray<T>(this.logSize - 1); - for (long i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java deleted file mode 100644 index a4f4eda9..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularIntArray<T> { - - private final int logSize; - private final T[] segment; - private final int mask; - private int currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularIntArray(final int logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.mask = this.getCapacity() - 1; // mask = 0..01..1 - } - - public int getCapacity() { - return this.segment.length; - } - - public T get(final int i) { - return this.segment[i & this.mask]; // risk of overflow - } - - public T getNext() { - int index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) & this.mask; - return this.segment[index]; - } - - public void put(final int i, final T o) { - this.segment[i & this.mask] = o; // risk of overflow - } - - public CircularIntArray<T> grow(final int b, final int t) { - final CircularIntArray<T> a = new CircularIntArray<T>(this.logSize + 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularIntArray<T> shrink(final int b, final int t) { - final CircularIntArray<T> a = new CircularIntArray<T>(this.logSize - 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java deleted file mode 100644 index a44239c5..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularModIntArray<T> { - - private final int logSize; - private final T[] segment; - private final int size; - - private int currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularModIntArray(final int logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.size = this.segment.length; - } - - public int getCapacity() { - return this.segment.length; - } - - public T get(final int i) { - return this.segment[i % this.size]; // risk of overflow - } - - public T getNext() { - int index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) % this.size; - return this.segment[index]; - } - - public void put(final int i, final T o) { - this.segment[i % this.size] = o; // risk of overflow - } - - public CircularModIntArray<T> grow(final int b, final int t) { - final CircularModIntArray<T> a = new CircularModIntArray<T>(this.logSize + 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularModIntArray<T> shrink(final int b, final int t) { - final CircularModIntArray<T> a = new CircularModIntArray<T>(this.logSize - 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java deleted file mode 100644 index cbab820e..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java +++ /dev/null @@ -1,305 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing; - -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; -import teetime.util.concurrent.workstealing.exception.OperationAbortedException; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class CircularWorkStealingDeque<T> { - - public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private final boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - } - - /** - * - * @param o - * a non-<code>null</code> element - */ - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final int numElementsToPush = 1; - final long currentSize = b - t; - final long newSize = currentSize + numElementsToPush; - if (newSize > a.getCapacity()) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + numElementsToPush; - } - - /** - * - * @param elements - * a non-<code>null</code> list - */ - public void pushBottomMultiple(final List<T> elements) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final int numElementsToPush = elements.size(); - final long currentSize = b - t; - final long newSize = currentSize + numElementsToPush; - if (newSize > a.getCapacity()) { - a = a.grow(b, t); - this.activeArray = a; - } - - for (final T elem : elements) { - a.put(b, elem); - } - - this.bottom = b + numElementsToPush; - } - - /** - * Returns and removes the latest element from this deque. - * - * @return - * <ul> - * <li><code>null</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public T popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.empty(); - } - T o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.empty(); - } - this.bottom = t + 1; - return o; - } - - /** - * Returns and removes the latest element from this deque. - * - * @return <i>the latest element</i>, otherwise it throws a <code>DequeIsEmptyException</code> - * - * @throws DequeIsEmptyException - */ - public T popBottomEx() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.emptyEx(); - } - T o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.emptyEx(); - } - this.bottom = t + 1; - return o; - } - - private void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>null</code> if the deque contains no elements, - * <li>(and also) <code>null</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public T steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.empty(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.empty(); - } else { - return this.abort(); - } - } - final T o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abort(); - } - return o; - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return <i>the oldest element</i>, otherwise it throws a <code>DequeIsEmptyException</code> or a <code>OperationAbortedException</code> - * - * @throws DequeIsEmptyException - * @throws OperationAbortedException - */ - public T stealEx() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.emptyEx(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.emptyEx(); - } else { - return this.abortEx(); - } - } - final T o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abortEx(); - } - return o; - } - - private T empty() { - return null; - } - - private T emptyEx() { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - - private T abort() { - return null; - } - - private T abortEx() { - throw OPERATION_ABORTED_EXCEPTION; - } - - private T regular(final T value) { - return value; - } - - /** - * Returns but does not remove the latest element from this deque.<br> - * <i>For debugging purposes</i> - * - * @return <ul> - * <li><code>null</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - public boolean isEmpty() { - final long t = this.top.get(); - final long b = this.bottom; - return t >= b; - } - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } - - @Override - public String toString() { - return this.activeArray.toString(); - } - -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java deleted file mode 100644 index 58294d9f..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class CircularWorkStealingDequeWithSentinel<T> { - - public static enum State { - REGULAR, EMPTY, ABORT - } - - public static class ReturnValue<T> { - private final State state; - private final T value; - - public ReturnValue(final State state, final T value) { - this.state = state; - this.value = value; - } - - public T getValue() { - return this.value; - } - - public State getState() { - return this.state; - } - } - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public ReturnValue<T> popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return new ReturnValue<T>(State.EMPTY, null); - } - ReturnValue<T> o = new ReturnValue<T>(State.REGULAR, a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = new ReturnValue<T>(State.EMPTY, null); - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><code>abort()</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public ReturnValue<T> steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return new ReturnValue<T>(State.EMPTY, null); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return new ReturnValue<T>(State.EMPTY, null); - } else { - return new ReturnValue<T>(State.ABORT, null); - } - } - final ReturnValue<T> o = new ReturnValue<T>(State.REGULAR, a.get(t)); - if (!this.casTop(t, t + 1)) { - return new ReturnValue<T>(State.ABORT, null); - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java deleted file mode 100644 index 3b0327d7..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> { - - public static enum State { - REGULAR, EMPTY, ABORT - } - - public static class ReturnValue<T> { - private State state; - private T value; - - public State getState() { - return this.state; - } - - public T getValue() { - return this.value; - } - - public ReturnValue<T> setState(final State state) { - this.state = state; - return this; - } - - public ReturnValue<T> setStateAndValue(final State state, final T value) { - this.state = state; - this.value = value; - return this; - } - } - - private final ThreadLocal<ReturnValue<T>> returnValue = new ThreadLocal<ReturnValue<T>>(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - public CircularWorkStealingDequeWithThreadLocalSentinel() { - this.returnValue.set(new ReturnValue<T>()); - } - - private boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public ReturnValue<T> popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.empty(); - } - ReturnValue<T> o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.empty(); - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><code>abort()</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public ReturnValue<T> steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.empty(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.empty(); - } else { - return this.abort(); - } - } - final ReturnValue<T> o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abort(); - } - return o; - } - - private ReturnValue<T> empty() { - return this.returnValue.get().setState(State.EMPTY); - } - - private ReturnValue<T> abort() { - return this.returnValue.get().setState(State.ABORT); - } - - private ReturnValue<T> regular(final T value) { - return this.returnValue.get().setStateAndValue(State.REGULAR, value); - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java deleted file mode 100644 index 8a45faef..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; -import teetime.util.concurrent.workstealing.exception.OperationAbortedException; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class ExceptionalCircularWorkStealingDeque<T> { - - public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - */ - public T popBottom() throws DequeIsEmptyException { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - throw DEQUE_IS_EMPTY_EXCEPTION; - } - final T o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - final boolean success = this.casTop(t, t + 1); - this.bottom = t + 1; - if (!success) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - * @throws OperationAbortedException - */ - public T steal() throws DequeIsEmptyException, OperationAbortedException { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } else { - throw OPERATION_ABORTED_EXCEPTION; - } - } - final T o = a.get(t); - if (!this.casTop(t, t + 1)) { - throw OPERATION_ABORTED_EXCEPTION; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java deleted file mode 100644 index 57501cfd..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class UntypedCircularWorkStealingDeque { - public static final Object EMPTY = new Object(); - public static final Object ABORT = new Object(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - } - - public void pushBottom(final Object o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public Object popBottom() { - long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - b = b - 1; - this.bottom = b; // reserve (avoid stealing) the current bottom element - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return EMPTY; - } - Object o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = EMPTY; - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<Object> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<Object> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public Object steal() { - final long t = this.top.get(); - final CircularArray<Object> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return EMPTY; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return EMPTY; - } else { - return ABORT; - } - } - final Object o = a.get(t); - if (!this.casTop(t, t + 1)) { - return ABORT; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public Object readBottom() { - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final Object o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java deleted file mode 100644 index 381aea46..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; -import teetime.util.concurrent.workstealing.exception.DequePopException; -import teetime.util.concurrent.workstealing.exception.OperationAbortedException; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public final class UntypedExceptionalCircularWorkStealingDeque { - - public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - } - - public void pushBottom(final Object o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - */ - public Object popBottom() throws DequePopException { - long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - throw DEQUE_IS_EMPTY_EXCEPTION; - } - final Object o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - final boolean success = this.casTop(t, t + 1); - this.bottom = t + 1; - if (!success) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<Object> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<Object> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - * @throws DequePopException - */ - public Object steal() throws DequePopException { - final long t = this.top.get(); - final CircularArray<Object> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } else { - throw OPERATION_ABORTED_EXCEPTION; - } - } - final Object o = a.get(t); - if (!this.casTop(t, t + 1)) { - throw OPERATION_ABORTED_EXCEPTION; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public Object readBottom() { - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final Object o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java deleted file mode 100644 index 08c58f61..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.exception; - -public final class DequeIsEmptyException extends DequePopException { - private static final long serialVersionUID = -6685406255103741724L; -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java deleted file mode 100644 index e4ff1860..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.exception; - -import teetime.util.StacklessException; - -public class DequePopException extends StacklessException { - private static final long serialVersionUID = 496512683536868149L; - -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java deleted file mode 100644 index f814ac5f..00000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.concurrent.workstealing.exception; - -public final class OperationAbortedException extends DequePopException { - private static final long serialVersionUID = 2983001853326344073L; -} diff --git a/src/main/resources/pipe-factories.conf b/src/main/resources/pipe-factories.conf index 3e3db904..05d552cb 100644 --- a/src/main/resources/pipe-factories.conf +++ b/src/main/resources/pipe-factories.conf @@ -1,5 +1,3 @@ teetime.framework.pipe.SingleElementPipeFactory -teetime.framework.pipe.OrderedGrowableArrayPipeFactory -teetime.framework.pipe.UnorderedGrowablePipeFactory teetime.framework.pipe.SpScPipeFactory -teetime.framework.pipe.UnboundedSpScPipeFactory +teetime.framework.pipe.UnboundedSpScPipeFactory \ No newline at end of file -- GitLab