summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-02-09 13:22:31 (EST)
committerEike Stepper2008-02-09 13:22:31 (EST)
commitd2e8de6408fde9b067cdc3bd5abae88ecf94570f (patch)
tree2c8e0901e2d824fd7fc6817ced2fa91ea970f1bb
parentf44c32e93055e72fad01137ed878453a28aa9e40 (diff)
downloadcdo-d2e8de6408fde9b067cdc3bd5abae88ecf94570f.zip
cdo-d2e8de6408fde9b067cdc3bd5abae88ecf94570f.tar.gz
cdo-d2e8de6408fde9b067cdc3bd5abae88ecf94570f.tar.bz2
[217117] Develop a HibernateStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217117
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/NonBlockingIntCounter.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/NonBlockingIntCounter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/NonBlockingIntCounter.java
new file mode 100644
index 0000000..27237dd
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/NonBlockingIntCounter.java
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.concurrent;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author Eike Stepper
+ */
+public final class NonBlockingIntCounter
+{
+ private AtomicInteger value;
+
+ public NonBlockingIntCounter()
+ {
+ this(0);
+ }
+
+ public NonBlockingIntCounter(int initialValue)
+ {
+ value = new AtomicInteger(initialValue);
+ }
+
+ public int getValue()
+ {
+ return value.get();
+ }
+
+ public int increment()
+ {
+ int v;
+ do
+ {
+ v = value.get();
+ } while (!value.compareAndSet(v, v + 1));
+
+ return v + 1;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Long.toString(getValue());
+ }
+}