[jboss-svn-commits] JBL Code SVN: r37213 - in labs/jbosstm/workspace/mlittle/STM-Arjuna/src: main/java/org/jboss/stm/internal and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 3 06:29:22 EDT 2011
Author: mark.little at jboss.com
Date: 2011-07-03 06:29:22 -0400 (Sun, 03 Jul 2011)
New Revision: 37213
Added:
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicArrayImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicBooleanImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicDoubleImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicFloatImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicIntegerImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicLongImpl.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/ArrayFactory.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicArray.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicBoolean.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicDouble.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFactory.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFloat.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicLong.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicArrayUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicBooleanUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicDoubleUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicFloatUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicIntegerUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicLongUnitTest.java
labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/ExtendedArrayUnitTest.java
Log:
Added LockFree annotation and basic atomic types.
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.annotations;
+
+import java.lang.annotation.*;
+
+// Means that the method is not transactional.
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ ElementType.METHOD })
+public @interface LockFree
+{
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicArrayImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicArrayImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicArrayImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,255 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.jboss.stm.RecoverableContainer;
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.RestoreState;
+import org.jboss.stm.annotations.SaveState;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicArray;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+
+// TODO maybe pull all of this into a separate jar
+
+/*
+ * TODO currently does not assume sparse list, i.e., requires
+ * contiguous.
+ */
+
+ at Transactional
+public class AtomicArrayImpl<E> implements AtomicArray<E>
+{
+ public static final int DEFAULT_SIZE = 10;
+
+ public AtomicArrayImpl ()
+ {
+ this(DEFAULT_SIZE);
+ }
+
+ public AtomicArrayImpl (int size)
+ {
+ _size = size;
+ _array = new ArrayList<E>(size);
+
+ for (int i = 0; i < _size; i++)
+ _array.add(i, null);
+ }
+
+ @WriteLock
+ public synchronized void empty ()
+ {
+ _array = new ArrayList<E>(_size);
+ }
+
+ @ReadLock
+ public synchronized E get (int index)
+ {
+ return _array.get(index);
+ }
+
+ @ReadLock
+ public synchronized boolean isEmpty ()
+ {
+ return _array.isEmpty();
+ }
+
+ @WriteLock
+ public synchronized void set (int index, E val)
+ {
+ if (basicType(val))
+ _array.set(index, val);
+ else
+ {
+ if (_container == null)
+ _container = new RecoverableContainer<E>();
+
+ _array.set(index, _container.enlist(val));
+ }
+ }
+
+ @ReadLock
+ public synchronized int size ()
+ {
+ return _array.size();
+ }
+
+ @SaveState
+ public void save_state (OutputObjectState os) throws IOException
+ {
+ if (_type == null)
+ _type = _array.get(0).getClass();
+
+ os.packInt(_size);
+
+ for (int i = 0; i < _array.size(); i++)
+ {
+ Object inst = _array.get(i);
+
+ if (_type.equals(Boolean.class))
+ os.packBoolean(((Boolean) inst).booleanValue());
+ else if (_type.equals(Byte.class))
+ os.packByte(((Byte) inst).byteValue());
+ else if (_type.equals(Short.class))
+ os.packShort(((Short) inst).shortValue());
+ else if (_type.equals(Integer.class))
+ os.packInt(((Integer) inst).intValue());
+ else if (_type.equals(Long.class))
+ os.packLong(((Long) inst).longValue());
+ else if (_type.equals(Float.class))
+ os.packFloat(((Float) inst).floatValue());
+ else if (_type.equals(Double.class))
+ os.packDouble(((Double) inst).doubleValue());
+ else if (_type.equals(Character.class))
+ os.packChar(((Character) inst).charValue());
+ else if (_type.equals(String.class))
+ os.packString((String) inst);
+ else
+ {
+ if (inst == null)
+ os.packBoolean(false);
+ else
+ {
+ os.packBoolean(true);
+
+ Uid temp = _container.getUidForHandle(_array.get(i));
+
+ /*
+ * Assume transactional object! Responsible for its own state, so we only
+ * track references.
+ */
+
+ try
+ {
+ temp.pack(os);
+ }
+ catch (final Exception ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @RestoreState
+ public void restore_state (InputObjectState os) throws IOException
+ {
+ _size = os.unpackInt();
+ _array = new ArrayList<E>(_size);
+
+ for (int i = 0; i < _size; i++)
+ _array.add(i, null);
+
+ for (int i = 0; i < _size; i++)
+ _array.add(i, null);
+
+ for (int i = 0; i < _size; i++)
+ {
+ if (_type.equals(Boolean.class))
+ _array.set(i, (E) ((Boolean) os.unpackBoolean()));
+ else if (_type.equals(Byte.class))
+ _array.set(i, (E) ((Byte) os.unpackByte()));
+ else if (_type.equals(Short.class))
+ _array.set(i, (E) ((Short) os.unpackShort()));
+ else if (_type.equals(Integer.class))
+ _array.set(i, (E) ((Integer) os.unpackInt()));
+ else if (_type.equals(Long.class))
+ _array.set(i, (E) ((Long) os.unpackLong()));
+ else if (_type.equals(Float.class))
+ _array.set(i, (E) ((Float) os.unpackFloat()));
+ else if (_type.equals(Double.class))
+ _array.set(i, (E) ((Double) os.unpackDouble()));
+ else if (_type.equals(Character.class))
+ _array.set(i, (E) ((Character) os.unpackChar()));
+ else if (_type.equals(String.class))
+ _array.set(i, (E) os.unpackString());
+ else
+ {
+ boolean ptr = os.unpackBoolean();
+
+ if (!ptr)
+ _array.set(i, null);
+ else
+ {
+ /*
+ * Assume transactional object! Responsible for its own state, so we only
+ * track references.
+ */
+
+ try
+ {
+ Uid temp = new Uid(Uid.nullUid());
+
+ temp.unpack(os);
+
+ _array.set(i, _container.getHandle(temp));
+ }
+ catch (final Exception ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+ }
+ }
+ }
+
+ private boolean basicType (E val)
+ {
+ if (_type == null)
+ _type = val.getClass();
+
+ if (_type.equals(Boolean.class))
+ return true;
+ else if (_type.equals(Byte.class))
+ return true;
+ else if (_type.equals(Short.class))
+ return true;
+ else if (_type.equals(Integer.class))
+ return true;
+ else if (_type.equals(Long.class))
+ return true;
+ else if (_type.equals(Float.class))
+ return true;
+ else if (_type.equals(Double.class))
+ return true;
+ else if (_type.equals(Character.class))
+ return true;
+ else if (_type.equals(String.class))
+ return true;
+ else
+ return false;
+ }
+
+ private ArrayList<E> _array;
+ private int _size;
+ private Class<?> _type;
+ private RecoverableContainer<E> _container; // used for non-basic types
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicBooleanImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicBooleanImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicBooleanImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicBoolean;
+import org.jboss.stm.types.AtomicFactory;
+import org.jboss.stm.types.AtomicInteger;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public class AtomicBooleanImpl implements AtomicBoolean
+{
+ public AtomicBooleanImpl ()
+ {
+ this(false);
+ }
+
+ public AtomicBooleanImpl (boolean s)
+ {
+ _state = s;
+ }
+
+ @WriteLock
+ public void set (boolean val)
+ {
+ _state = val;
+ }
+
+ @ReadLock
+ public boolean get ()
+ {
+ return _state;
+ }
+
+ @ReadLock
+ public AtomicBoolean and (AtomicBoolean param)
+ {
+ return AtomicFactory.instance().createBoolean(_state & param.get());
+ }
+
+ @WriteLock
+ public AtomicBoolean flip ()
+ {
+ _state = !_state;
+
+ return this;
+ }
+
+ @ReadLock
+ public AtomicBoolean not ()
+ {
+ return AtomicFactory.instance().createBoolean(!_state);
+ }
+
+ @ReadLock
+ public AtomicBoolean or (AtomicBoolean param)
+ {
+ return AtomicFactory.instance().createBoolean(_state | param.get());
+ }
+
+ @ReadLock
+ public AtomicBoolean xor (AtomicBoolean param)
+ {
+ return AtomicFactory.instance().createBoolean(_state ^ param.get());
+ }
+
+ @State
+ private boolean _state;
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicDoubleImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicDoubleImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicDoubleImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicDouble;
+import org.jboss.stm.types.AtomicFloat;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public class AtomicDoubleImpl implements AtomicDouble
+{
+ public AtomicDoubleImpl ()
+ {
+ this(0);
+ }
+
+ public AtomicDoubleImpl (double s)
+ {
+ _state = s;
+ }
+
+ @WriteLock
+ public void set (double val)
+ {
+ _state = val;
+ }
+
+ @ReadLock
+ public double get ()
+ {
+ return _state;
+ }
+
+ @WriteLock
+ public AtomicDouble add (AtomicDouble obj)
+ {
+ if (obj != null)
+ {
+ _state += obj.get();
+ }
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicDouble subtract (AtomicDouble obj)
+ {
+ if (obj != null)
+ {
+ _state -= obj.get();
+ }
+
+ return this;
+ }
+
+ @State
+ private double _state;
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicFloatImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicFloatImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicFloatImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicFloat;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public class AtomicFloatImpl implements AtomicFloat
+{
+ public AtomicFloatImpl ()
+ {
+ this(0);
+ }
+
+ public AtomicFloatImpl (float s)
+ {
+ _state = s;
+ }
+
+ @WriteLock
+ public void set (float val)
+ {
+ _state = val;
+ }
+
+ @ReadLock
+ public float get ()
+ {
+ return _state;
+ }
+
+ @WriteLock
+ public AtomicFloat add (AtomicFloat obj)
+ {
+ if (obj != null)
+ {
+ _state += obj.get();
+ }
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicFloat subtract (AtomicFloat obj)
+ {
+ if (obj != null)
+ {
+ _state -= obj.get();
+ }
+
+ return this;
+ }
+
+ @State
+ private float _state;
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicIntegerImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicIntegerImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicIntegerImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicInteger;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public class AtomicIntegerImpl implements AtomicInteger
+{
+ public AtomicIntegerImpl ()
+ {
+ this(0);
+ }
+
+ public AtomicIntegerImpl (int s)
+ {
+ _state = s;
+ }
+
+ @WriteLock
+ public void set (int val)
+ {
+ _state = val;
+ }
+
+ @WriteLock
+ public AtomicInteger increment ()
+ {
+ _state++;
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicInteger decrement ()
+ {
+ _state--;
+
+ return this;
+ }
+
+ @ReadLock
+ public int get ()
+ {
+ return _state;
+ }
+
+ @WriteLock
+ public AtomicInteger add (AtomicInteger obj)
+ {
+ if (obj != null)
+ {
+ _state += obj.get();
+ }
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicInteger subtract (AtomicInteger obj)
+ {
+ if (obj != null)
+ {
+ _state -= obj.get();
+ }
+
+ return this;
+ }
+
+ @State
+ private int _state;
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicLongImpl.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicLongImpl.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/types/AtomicLongImpl.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.internal.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.types.AtomicInteger;
+import org.jboss.stm.types.AtomicLong;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public class AtomicLongImpl implements AtomicLong
+{
+ public AtomicLongImpl ()
+ {
+ this(0);
+ }
+
+ public AtomicLongImpl (long s)
+ {
+ _state = s;
+ }
+
+ @WriteLock
+ public void set (long val)
+ {
+ _state = val;
+ }
+
+ @WriteLock
+ public AtomicLong increment ()
+ {
+ _state++;
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicLong decrement ()
+ {
+ _state--;
+
+ return this;
+ }
+
+ @ReadLock
+ public long get ()
+ {
+ return _state;
+ }
+
+ @WriteLock
+ public AtomicLong add (AtomicLong obj)
+ {
+ if (obj != null)
+ {
+ _state += obj.get();
+ }
+
+ return this;
+ }
+
+ @WriteLock
+ public AtomicLong subtract (AtomicLong obj)
+ {
+ if (obj != null)
+ {
+ _state -= obj.get();
+ }
+
+ return this;
+ }
+
+ @State
+ private long _state;
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/ArrayFactory.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/ArrayFactory.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/ArrayFactory.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.RecoverableContainer;
+import org.jboss.stm.internal.types.AtomicArrayImpl;
+
+// TODO maybe pull all of this into a separate jar
+
+public class ArrayFactory<E>
+{
+ @SuppressWarnings("unchecked")
+ public static ArrayFactory instance ()
+ {
+ return _theFactory;
+ }
+
+ public AtomicArray<E> createArray ()
+ {
+ return createArray(AtomicArrayImpl.DEFAULT_SIZE);
+ }
+
+ public AtomicArray<E> createArray (int size)
+ {
+ return _afContainer.enlist(new AtomicArrayImpl<E>(size));
+ }
+
+ private RecoverableContainer<AtomicArray<E>> _afContainer = new RecoverableContainer<AtomicArray<E>>();
+
+ @SuppressWarnings("unchecked")
+ private static final ArrayFactory _theFactory = new ArrayFactory();
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicArray.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicArray.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicArray.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+
+// TODO maybe pull all of this into a separate jar
+
+/**
+ * An array of basic types.
+ */
+
+ at Transactional
+public interface AtomicArray<E>
+{
+ @ReadLock
+ public int size ();
+
+ @ReadLock
+ public boolean isEmpty ();
+
+ @WriteLock
+ public void empty ();
+
+ @ReadLock
+ public E get (int index);
+
+ @WriteLock
+ public void set (int index, E val);
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicBoolean.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicBoolean.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicBoolean.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public interface AtomicBoolean
+{
+ @WriteLock
+ public void set (boolean val);
+
+ @ReadLock
+ public boolean get ();
+
+ @ReadLock
+ public AtomicBoolean not ();
+
+ @WriteLock
+ public AtomicBoolean flip ();
+
+ /**
+ * The following operations produce side-effects in that the
+ * return values are new objects based on the current state of the
+ * current object and the parameter. If performed within the scope
+ * of a transaction, the objects used to determine the return value may
+ * have their states changed making the return invalid.
+ */
+
+ // TODO make the returned value state roll back too?
+
+ @ReadLock
+ public AtomicBoolean and (AtomicBoolean param);
+
+ @ReadLock
+ public AtomicBoolean or (AtomicBoolean param);
+
+ @ReadLock
+ public AtomicBoolean xor (AtomicBoolean param);
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicDouble.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicDouble.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicDouble.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public interface AtomicDouble
+{
+ @WriteLock
+ public void set (double val);
+
+ @ReadLock
+ public double get ();
+
+ @WriteLock
+ public AtomicDouble add (AtomicDouble obj);
+
+ @WriteLock
+ public AtomicDouble subtract (AtomicDouble obj);
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFactory.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFactory.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFactory.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.RecoverableContainer;
+import org.jboss.stm.internal.types.AtomicBooleanImpl;
+import org.jboss.stm.internal.types.AtomicDoubleImpl;
+import org.jboss.stm.internal.types.AtomicFloatImpl;
+import org.jboss.stm.internal.types.AtomicIntegerImpl;
+import org.jboss.stm.internal.types.AtomicLongImpl;
+
+// TODO maybe pull all of this into a separate jar
+
+public class AtomicFactory
+{
+ public static AtomicFactory instance ()
+ {
+ return _theFactory;
+ }
+
+ public AtomicBoolean createBoolean ()
+ {
+ return createBoolean(false);
+ }
+
+ public AtomicBoolean createBoolean (boolean initialValue)
+ {
+ return _abContainer.enlist(new AtomicBooleanImpl(initialValue));
+ }
+
+ public AtomicInteger createInteger ()
+ {
+ return createInteger(0);
+ }
+
+ public AtomicInteger createInteger (int initialValue)
+ {
+ return _aiContainer.enlist(new AtomicIntegerImpl(initialValue));
+ }
+
+ public AtomicLong createLong ()
+ {
+ return createLong(0);
+ }
+
+ public AtomicLong createLong (long initialValue)
+ {
+ return _alContainer.enlist(new AtomicLongImpl(initialValue));
+ }
+
+ public AtomicFloat createFloat ()
+ {
+ return createFloat(0);
+ }
+
+ public AtomicFloat createFloat (float initialValue)
+ {
+ return _afContainer.enlist(new AtomicFloatImpl(initialValue));
+ }
+
+ public AtomicDouble createDouble ()
+ {
+ return createDouble(0);
+ }
+
+ public AtomicDouble createDouble (double initialValue)
+ {
+ return _adContainer.enlist(new AtomicDoubleImpl(initialValue));
+ }
+
+ private AtomicFactory ()
+ {
+ }
+
+ private RecoverableContainer<AtomicInteger> _aiContainer = new RecoverableContainer<AtomicInteger>();
+ private RecoverableContainer<AtomicFloat> _afContainer = new RecoverableContainer<AtomicFloat>();
+ private RecoverableContainer<AtomicDouble> _adContainer = new RecoverableContainer<AtomicDouble>();
+ private RecoverableContainer<AtomicLong> _alContainer = new RecoverableContainer<AtomicLong>();
+ private RecoverableContainer<AtomicBoolean> _abContainer = new RecoverableContainer<AtomicBoolean>();
+
+ private static final AtomicFactory _theFactory = new AtomicFactory();
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFloat.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFloat.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicFloat.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public interface AtomicFloat
+{
+ @WriteLock
+ public void set (float val);
+
+ @ReadLock
+ public float get ();
+
+ @WriteLock
+ public AtomicFloat add (AtomicFloat obj);
+
+ @WriteLock
+ public AtomicFloat subtract (AtomicFloat obj);
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicLong.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicLong.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/types/AtomicLong.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+
+// TODO maybe pull all of this into a separate jar
+
+ at Transactional
+public interface AtomicLong
+{
+ @WriteLock
+ public void set (long val);
+
+ @ReadLock
+ public long get ();
+
+ @WriteLock
+ public AtomicLong increment ();
+
+ @WriteLock
+ public AtomicLong decrement ();
+
+ @WriteLock
+ public AtomicLong add (AtomicLong obj);
+
+ @WriteLock
+ public AtomicLong subtract (AtomicLong obj);
+}
\ No newline at end of file
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicArrayUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicArrayUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicArrayUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicArrayUnitTest extends TestCase
+{
+ @SuppressWarnings("unchecked")
+ public void test ()
+ {
+ AtomicArray<Integer> a1 = ArrayFactory.instance().createArray();
+
+ for (int i = 0; i < a1.size(); i++)
+ a1.set(i, i);
+
+ for (int j = 0; j < a1.size(); j++)
+ assertTrue(a1.get(j).equals(j));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTransaction ()
+ {
+ AtomicAction act = new AtomicAction();
+ AtomicArray<Integer> a1 = ArrayFactory.instance().createArray(10);
+
+ assertEquals(a1.size(), 10);
+
+ for (int i = 0; i < a1.size(); i++)
+ a1.set(i, 0);
+
+ act.begin();
+
+ a1.set(0, 1);
+ a1.set(1, 2);
+
+ assertTrue(a1.get(0).equals(1));
+ assertTrue(a1.get(1).equals(2));
+
+ act.abort();
+
+ assertTrue(a1.get(0).equals(0));
+ assertTrue(a1.get(1).equals(0));
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicBooleanUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicBooleanUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicBooleanUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicBooleanUnitTest extends TestCase
+{
+ public void test ()
+ {
+ AtomicBoolean ab = AtomicFactory.instance().createBoolean();
+
+ assertEquals(ab.get(), false);
+
+ ab.set(true);
+
+ assertEquals(ab.get(), true);
+
+ AtomicBoolean temp = AtomicFactory.instance().createBoolean(false);
+
+ assertEquals(temp.get(), false);
+
+ assertFalse((ab.and(temp).get()));
+ assertTrue((ab.or(temp).get()));
+
+ assertTrue((ab.xor(temp).get()));
+
+ temp.set(true);
+
+ assertFalse((ab.xor(temp).get()));
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicDoubleUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicDoubleUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicDoubleUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicDoubleUnitTest extends TestCase
+{
+ public void test ()
+ {
+ AtomicDouble ad = AtomicFactory.instance().createDouble();
+
+ assertEquals(ad.get(), (double) 0);
+
+ ad.set(1);
+
+ assertEquals(ad.get(), (double) 1);
+
+ AtomicDouble temp = AtomicFactory.instance().createDouble(667);
+
+ assertEquals(temp.get(), (double) 667);
+
+ assertEquals(temp.subtract(ad).get(), (double) 666);
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicFloatUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicFloatUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicFloatUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicFloatUnitTest extends TestCase
+{
+ public void test ()
+ {
+ AtomicFloat af = AtomicFactory.instance().createFloat();
+
+ assertEquals(af.get(), (float) 0);
+
+ af.set(1);
+
+ assertEquals(af.get(), (float) 1);
+
+ AtomicFloat temp = AtomicFactory.instance().createFloat(667);
+
+ assertEquals(temp.get(), (float) 667);
+
+ assertEquals(temp.subtract(af).get(), (float) 666);
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicIntegerUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicIntegerUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicIntegerUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicIntegerUnitTest extends TestCase
+{
+ public void test ()
+ {
+ AtomicInteger ai = AtomicFactory.instance().createInteger();
+
+ assertEquals(ai.get(), 0);
+
+ ai.set(1);
+
+ assertEquals(ai.get(), 1);
+
+ AtomicInteger temp = AtomicFactory.instance().createInteger(667);
+
+ assertEquals(temp.get(), 667);
+
+ assertEquals(temp.subtract(ai).get(), 666);
+
+ assertEquals(ai.increment().get(), 2);
+
+ assertEquals(ai.decrement().get(), 1);
+ }
+
+ public void testTransaction ()
+ {
+ AtomicAction act = new AtomicAction();
+ AtomicInteger ai = AtomicFactory.instance().createInteger();
+
+ assertEquals(ai.get(), 0);
+
+ /*
+ * Do this within a transaction so we can roll it all back
+ * afterwards.
+ */
+
+ act.begin();
+
+ ai.set(1);
+
+ assertEquals(ai.get(), 1);
+
+ act.abort();
+
+ assertEquals(ai.get(), 0);
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicLongUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicLongUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/AtomicLongUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class AtomicLongUnitTest extends TestCase
+{
+ public void test ()
+ {
+ AtomicLong al = AtomicFactory.instance().createLong();
+
+ assertEquals(al.get(), 0);
+
+ al.set(1);
+
+ assertEquals(al.get(), 1);
+
+ AtomicLong temp = AtomicFactory.instance().createLong(667);
+
+ assertEquals(temp.get(), 667);
+
+ assertEquals(temp.subtract(al).get(), 666);
+
+ assertEquals(al.increment().get(), 2);
+
+ assertEquals(al.decrement().get(), 1);
+ }
+}
Added: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/ExtendedArrayUnitTest.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/ExtendedArrayUnitTest.java (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/test/java/org/jboss/stm/types/ExtendedArrayUnitTest.java 2011-07-03 10:29:22 UTC (rev 37213)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stm.types;
+
+import org.jboss.stm.annotations.ReadLock;
+import org.jboss.stm.annotations.State;
+import org.jboss.stm.annotations.Transactional;
+import org.jboss.stm.annotations.WriteLock;
+import org.jboss.stm.internal.types.AtomicArrayImpl;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the AtomicInteger class.
+ *
+ * @author Mark Little
+ */
+
+public class ExtendedArrayUnitTest extends TestCase
+{
+ @Transactional
+ public interface Sample
+ {
+ @WriteLock
+ public void set (int val);
+
+ @ReadLock
+ public int get ();
+ }
+
+ @Transactional
+ public class SampleLockable implements Sample
+ {
+ public SampleLockable ()
+ {
+ this(0);
+ }
+
+ public SampleLockable (int val)
+ {
+ _val = val;
+ }
+
+ @ReadLock
+ public int get ()
+ {
+ return _val;
+ }
+
+ @WriteLock
+ public void set (int val)
+ {
+ _val = val;
+ }
+
+ @State
+ private int _val;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void test ()
+ {
+ AtomicArray<Sample> a1 = ArrayFactory.instance().createArray();
+
+ a1.set(0, new SampleLockable());
+ a1.set(1, new SampleLockable());
+
+ assertEquals(a1.get(0).get(), 0);
+ assertEquals(a1.get(1).get(), 0);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTransaction ()
+ {
+ AtomicAction act = new AtomicAction();
+ AtomicArray<Sample> a1 = ArrayFactory.instance().createArray();
+
+ a1.set(0, new SampleLockable());
+ a1.set(1, new SampleLockable());
+
+ assertEquals(a1.get(0).get(), 0);
+ assertEquals(a1.get(1).get(), 0);
+
+ act.begin();
+
+ a1.set(0, new SampleLockable(1));
+ a1.set(1, new SampleLockable(1));
+
+ assertEquals(a1.get(0).get(), 1);
+ assertEquals(a1.get(1).get(), 1);
+
+ act.abort();
+
+ assertEquals(a1.get(0).get(), 0);
+ assertEquals(a1.get(1).get(), 0);
+ }
+}
More information about the jboss-svn-commits
mailing list