MongoDB C++ Driver  legacy-1.1.2
atomic_intrinsics_gcc_atomic.h
1 /* Copyright 2012 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
21 #pragma once
22 
23 namespace mongo {
24 
28 template <typename T, typename IsTLarge = void>
30 public:
31  static T compareAndSwap(volatile T* dest, T expected, T newValue) {
32  __atomic_compare_exchange(
33  dest, &expected, &newValue, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
34  return expected;
35  }
36 
37  static T swap(volatile T* dest, T newValue) {
38  T result;
39  __atomic_exchange(dest, &newValue, &result, __ATOMIC_SEQ_CST);
40  return result;
41  }
42 
43  static T load(volatile const T* value) {
44  T result;
45  __atomic_load(value, &result, __ATOMIC_SEQ_CST);
46  return result;
47  }
48 
49  static T loadRelaxed(volatile const T* value) {
50  T result;
51  __atomic_load(value, &result, __ATOMIC_RELAXED);
52  return result;
53  }
54 
55  static void store(volatile T* dest, T newValue) {
56  __atomic_store(dest, &newValue, __ATOMIC_SEQ_CST);
57  }
58 
59  static T fetchAndAdd(volatile T* dest, T increment) {
60  return __atomic_fetch_add(dest, increment, __ATOMIC_SEQ_CST);
61  }
62 
63 private:
66 };
67 
68 } // namespace mongo
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Instantiation of AtomicIntrinsics<> for all word types T.
Definition: atomic_intrinsics_gcc_atomic.h:29