activemq-cpp-3.8.2
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 
25 namespace decaf {
26 namespace util {
27 namespace concurrent {
28 namespace atomic {
29 
33  template< typename T >
35  private:
36 
37  volatile void* value;
38 
39  private:
40 
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 void * getAndSet(volatile void **target, void *value)
#define NULL
Definition: Config.h:33
std::string toString() const
static bool compareAndSet(volatile void **target, void *expect, void *update)
T * getAndSet(T *newValue)
Atomically sets to the given value and returns the old value.
Definition: AtomicReference.h:90
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
std::string toString() const
Returns the String representation of the current value.
Definition: AtomicReference.h:98
An Pointer reference that may be updated atomically.
Definition: AtomicReference.h:34
AtomicReference()
Definition: AtomicReference.h:46
virtual ~AtomicReference()
Definition: AtomicReference.h:49
AtomicReference(T *value)
Definition: AtomicReference.h:47
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25