activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r739373 - in /activemq/activemq-cpp/trunk/src: main/Makefile.am test/Makefile.am test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp test/decaf/util/concurrent/atomic/AtomicReferenceTest.h test/testRegistry.cpp
Date Fri, 30 Jan 2009 18:44:26 GMT
Author: tabish
Date: Fri Jan 30 18:44:25 2009
New Revision: 739373

URL: http://svn.apache.org/viewvc?rev=739373&view=rev
Log:
Adds an AtomicReference to decaf's atomic package to allow for safe pointer exchange.

Added:
    activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp
  (with props)
    activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h
  (with props)
Modified:
    activemq/activemq-cpp/trunk/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/test/Makefile.am
    activemq/activemq-cpp/trunk/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/Makefile.am?rev=739373&r1=739372&r2=739373&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/main/Makefile.am Fri Jan 30 18:44:25 2009
@@ -356,6 +356,7 @@
     decaf/util/concurrent/TimeoutException.h \
     decaf/util/concurrent/atomic/AtomicBoolean.h \
     decaf/util/concurrent/atomic/AtomicInteger.h \
+    decaf/util/concurrent/atomic/AtomicReference.h \
     decaf/util/concurrent/locks/Lock.h \
     decaf/util/concurrent/locks/Condition.h \
     decaf/util/concurrent/locks/ReadWriteLock.h \

Modified: activemq/activemq-cpp/trunk/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/Makefile.am?rev=739373&r1=739372&r2=739373&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/test/Makefile.am Fri Jan 30 18:44:25 2009
@@ -107,6 +107,7 @@
   decaf/util/concurrent/TimeUnitTest.cpp \
   decaf/util/concurrent/atomic/AtomicBooleanTest.cpp \
   decaf/util/concurrent/atomic/AtomicIntegerTest.cpp \
+  decaf/util/concurrent/atomic/AtomicReferenceTest.cpp \
   decaf/nio/BufferTest.cpp \
   testRegistry.cpp \
   main.cpp
@@ -203,6 +204,7 @@
   decaf/util/concurrent/TimeUnitTest.h \
   decaf/util/concurrent/atomic/AtomicBooleanTest.h \
   decaf/util/concurrent/atomic/AtomicIntegerTest.h \
+  decaf/util/concurrent/atomic/AtomicReferenceTest.h \
   decaf/nio/BufferTest.h  
 
 ## include activemq/wireformat/openwire/marshal/v1/srcmakefile.mk

Added: activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp?rev=739373&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp
Fri Jan 30 18:44:25 2009
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include "AtomicReferenceTest.h"
+
+#include <decaf/util/concurrent/atomic/AtomicReference.h>
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Long.h>
+#include <decaf/lang/Thread.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::util::concurrent::atomic;
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testConstructor() {
+    AtomicReference<int> ai;
+    CPPUNIT_ASSERT( ai.get() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testConstructor2() {
+    int value = 999;
+    AtomicReference<int> ai( &value );
+    CPPUNIT_ASSERT( *( ai.get() ) == 999 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testGetSet() {
+    int value1 = 2;
+    AtomicReference<int> ai( &value1 );
+    CPPUNIT_ASSERT( 2 == *( ai.get() ) );
+    int value2 = 5;
+    ai.set( &value2 );
+    CPPUNIT_ASSERT( 5 == *( ai.get() ) );
+    int value3 = 6;
+    ai.set( &value3 );
+    CPPUNIT_ASSERT( 6 == *( ai.get() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testCompareAndSet() {
+    int value1 = 25;
+    int value2 = 50;
+    int value3 = 75;
+    AtomicReference<int> ai( &value1 );
+    CPPUNIT_ASSERT( ai.compareAndSet( &value1, &value2 ) );
+    CPPUNIT_ASSERT( &value2 == ai.get() );
+    CPPUNIT_ASSERT( ai.compareAndSet( &value2, &value1 ) );
+    CPPUNIT_ASSERT( &value1 == ai.get() );
+    CPPUNIT_ASSERT( !ai.compareAndSet( &value2, &value3 ) );
+    CPPUNIT_ASSERT( ai.get() != &value3 );
+    CPPUNIT_ASSERT( ai.compareAndSet( &value1, &value2 ) );
+    CPPUNIT_ASSERT( &value2 == ai.get() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+class MyRefedRunnable: public Runnable {
+private:
+
+    AtomicReference<int>* aip;
+
+public:
+
+    int value1;
+    int value2;
+    int value3;
+
+public:
+
+    MyRefedRunnable( AtomicReference<int>* ai ) :
+        aip( ai ), value1( 1 ), value2( 2 ), value3( 3 ) {
+    }
+
+    virtual void run() {
+
+        while( !aip->compareAndSet( &value2, &value3 ) ) {
+            Thread::yield();
+        }
+    }
+
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testCompareAndSetInMultipleThreads() {
+
+    AtomicReference<int> ai;
+    MyRefedRunnable runnable( &ai );
+    ai.set( &runnable.value1 );
+    Thread t( &runnable );
+
+    try {
+
+        t.start();
+        CPPUNIT_ASSERT( ai.compareAndSet( &runnable.value1, &runnable.value2 ) );
+        t.join();
+        CPPUNIT_ASSERT( ai.get() == &runnable.value3 );
+
+    } catch( Exception& e ) {
+        CPPUNIT_FAIL( "Should Not Throw" );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testGetAndSet() {
+    int value1 = 50;
+    int value2 = 75;
+    int value3 = 25;
+    int value4 = 100;
+    AtomicReference<int> ai( &value1 );
+    CPPUNIT_ASSERT( &value1 == ai.getAndSet( &value2 ) );
+    CPPUNIT_ASSERT( &value2 == ai.getAndSet( &value3 ) );
+    CPPUNIT_ASSERT( &value3 == ai.getAndSet( &value4 ) );
+    CPPUNIT_ASSERT( &value4 == ai.get() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void AtomicReferenceTest::testToString() {
+    int value;
+    AtomicReference<int> ai;
+    CPPUNIT_ASSERT( ai.toString() == Integer::toString( 0 ) );
+    ai.set( &value );
+    CPPUNIT_ASSERT( ai.toString() == Integer::toString( (long long)&value ) );
+}

Propchange: activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h?rev=739373&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h
(added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h
Fri Jan 30 18:44:25 2009
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#ifndef _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCETEST_H_
+#define _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+namespace atomic {
+
+    class AtomicReferenceTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( AtomicReferenceTest );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testConstructor2 );
+        CPPUNIT_TEST( testGetSet );
+        CPPUNIT_TEST( testCompareAndSet );
+        CPPUNIT_TEST( testCompareAndSetInMultipleThreads );
+        CPPUNIT_TEST( testGetAndSet );
+        CPPUNIT_TEST( testToString );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        AtomicReferenceTest() {}
+        virtual ~AtomicReferenceTest() {}
+
+        void testConstructor();
+        void testConstructor2();
+        void testGetSet();
+        void testCompareAndSet();
+        void testCompareAndSetInMultipleThreads();
+        void testGetAndSet();
+        void testToString();
+
+    };
+
+}}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCETEST_H_ */

Propchange: activemq/activemq-cpp/trunk/src/test/decaf/util/concurrent/atomic/AtomicReferenceTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/testRegistry.cpp?rev=739373&r1=739372&r2=739373&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/testRegistry.cpp Fri Jan 30 18:44:25 2009
@@ -198,12 +198,14 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::ThreadPoolTest );
 //#include <decaf/util/concurrent/TimeUnitTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::TimeUnitTest );
-//
-//#include <decaf/util/concurrent/atomic/AtomicBooleanTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicBooleanTest );
-//#include <decaf/util/concurrent/atomic/AtomicIntegerTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicIntegerTest );
-//
+
+#include <decaf/util/concurrent/atomic/AtomicBooleanTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicBooleanTest );
+#include <decaf/util/concurrent/atomic/AtomicIntegerTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicIntegerTest );
+#include <decaf/util/concurrent/atomic/AtomicReferenceTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicReferenceTest );
+
 //#include <decaf/util/DateTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::DateTest );
 //#include <decaf/util/UUIDTest.h>



Mime
View raw message