activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r689641 - in /activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic: AtomicBoolean.cpp AtomicBoolean.h
Date Wed, 27 Aug 2008 22:04:38 GMT
Author: tabish
Date: Wed Aug 27 15:04:38 2008
New Revision: 689641

URL: http://svn.apache.org/viewvc?rev=689641&view=rev
Log:
Add a start on the Atomic Package

Added:
    activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.h

Added: activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.cpp?rev=689641&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.cpp Wed
Aug 27 15:04:38 2008
@@ -0,0 +1,50 @@
+/*
+ * 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 "AtomicBoolean.h"
+
+#include <decaf/lang/Boolean.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::util::concurrent::atomic;
+
+////////////////////////////////////////////////////////////////////////////////
+AtomicBoolean::AtomicBoolean() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool AtomicBoolean::compareAndSet( bool expect, bool update ) {
+    // TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool AtomicBoolean::getAndSet( bool newValue ) {
+    for(;;) {
+        bool current = get();
+        if( compareAndSet( current, newValue ) ) {
+            return current;
+        }
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string AtomicBoolean::toString() {
+    return Boolean::toString( this->value ? true : false );
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.h?rev=689641&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/atomic/AtomicBoolean.h Wed
Aug 27 15:04:38 2008
@@ -0,0 +1,99 @@
+/*
+ * 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_ATOMICBOOLEAN_H_
+#define _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICBOOLEAN_H_
+
+#include <string>
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+namespace atomic {
+
+    /**
+     * A boolean value that may be updated atomically. An AtomicBoolean is used
+     * in applications such as atomically updated flags, and cannot be used as a
+     * replacement for a Boolean.
+     */
+    class DECAF_API AtomicBoolean {
+    private:
+
+        volatile int value;
+
+    public:
+
+        /**
+         * Creates a new AtomicBoolean whose initial value is false.
+         */
+        AtomicBoolean();
+
+        /**
+         * Creates a new AtomicBoolean with the initial value.
+         * @param initialValue - The initial value of this boolean.
+         */
+        AtomicBoolean( bool initialValue );
+
+        virtual ~AtomicBoolean() {}
+
+        /**
+         * Gets the current value of this AtomicBoolean.
+         * @returns the currently set value.
+         */
+        bool get() const {
+            return value == 0 ? false : true;
+        }
+
+        /**
+         * Unconditionally sets to the given value.
+         * @param newValue - the new value
+         */
+        void set( bool newValue ) {
+            this->value = newValue ? 1 : 0;
+        }
+
+        /**
+         * Atomically sets the value to the given updated value if the current
+         * value == the expected value.
+         *
+         * @param expect - the expected value
+         * @param update - the new value
+         * @returns true if successful. False return indicates that the actual value
+         * was not equal to the expected value.
+         */
+        bool compareAndSet( bool expect, bool update );
+
+        /**
+         * Atomically sets to the given value and returns the previous value.
+         *
+         * @param newValue - the new value
+         * @returns the previous value
+         */
+        bool getAndSet( bool newValue );
+
+        /**
+         * Returns the String representation of the current value.
+         * @returns the String representation of the current value.
+         */
+        std::string toString();
+
+    };
+
+}}}}
+
+#endif /*_DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICBOOLEAN_H_*/



Mime
View raw message