activemq-cpp-3.9.5
AtomicReference.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCE_H_
19#define _DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCE_H_
20
21#include <decaf/util/Config.h>
22#include <decaf/lang/Long.h>
24
25namespace decaf {
26namespace util {
27namespace concurrent {
28namespace atomic {
29
33 template< typename T >
34 class AtomicReference {
35 private:
36
37 volatile void* value;
38
39 private:
40
41 AtomicReference(const AtomicReference&);
42 AtomicReference& operator= (const AtomicReference&);
43
44 public:
45
46 AtomicReference() : value( NULL ) {}
47 AtomicReference(T* value) : value((void*)value) {}
48
49 virtual ~AtomicReference() {}
50
55 T* get() const {
56 return (T*)value;
57 }
58
65 void set( T* newValue ) {
66 internal::util::concurrent::Atomics::getAndSet(&this->value, (void*)newValue);
67 }
68
79 bool compareAndSet( T* expect, T* update ) {
80 return internal::util::concurrent::Atomics::compareAndSet(&this->value, (void*)expect, (void*)update);
81 }
82
90 T* getAndSet( T* newValue ) {
91 return (T*)internal::util::concurrent::Atomics::getAndSet(&this->value, (void*)newValue);
92 }
93
98 std::string toString() const {
99 return decaf::lang::Long::toString( (long long)this->value );
100 }
101
102 };
103
104}}}}
105
106#endif /*_DECAF_UTIL_CONCURRENT_ATOMIC_ATOMICREFERENCE_H_*/
static bool compareAndSet(volatile void **target, void *expect, void *update)
static void * getAndSet(volatile void **target, void *value)
std::string toString() const
AtomicReference(T *value)
Definition AtomicReference.h:47
bool compareAndSet(T *expect, T *update)
Atomically sets the value to the given updated value if the current value == the expected value.
Definition AtomicReference.h:79
virtual ~AtomicReference()
Definition AtomicReference.h:49
T * getAndSet(T *newValue)
Atomically sets to the given value and returns the old value.
Definition AtomicReference.h:90
std::string toString() const
Returns the String representation of the current value.
Definition AtomicReference.h:98
void set(T *newValue)
Sets the Current value of this Reference.
Definition AtomicReference.h:65
T * get() const
Gets the Current Value.
Definition AtomicReference.h:55
AtomicReference()
Definition AtomicReference.h:46
#define NULL
Definition Config.h:33
Definition AtomicBoolean.h:27
Definition AbstractExecutorService.h:28
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25