libfoedus-core
FOEDUS Core Library
atomic_fences.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ASSORTED_ATOMIC_FENCES_HPP_
19 #define FOEDUS_ASSORTED_ATOMIC_FENCES_HPP_
20 
21 #include <stdint.h>
22 
35 namespace foedus {
36 namespace assorted {
37 
46 inline void memory_fence_acquire() {
47  ::__atomic_thread_fence(__ATOMIC_ACQUIRE);
48 }
49 
58 inline void memory_fence_release() {
59  ::__atomic_thread_fence(__ATOMIC_RELEASE);
60 }
61 
69 inline void memory_fence_acq_rel() {
70  ::__atomic_thread_fence(__ATOMIC_ACQ_REL);
71 }
72 
81 inline void memory_fence_consume() {
82  ::__atomic_thread_fence(__ATOMIC_CONSUME);
83 }
84 
92 inline void memory_fence_seq_cst() {
93  ::__atomic_thread_fence(__ATOMIC_SEQ_CST);
94 }
95 
102 template <typename T>
103 inline T atomic_load_seq_cst(const T* target) {
104  return ::__atomic_load_n(target, __ATOMIC_SEQ_CST);
105 }
106 
113 template <typename T>
114 inline T atomic_load_acquire(const T* target) {
115  return ::__atomic_load_n(target, __ATOMIC_ACQUIRE);
116 }
117 
124 template <typename T>
125 inline T atomic_load_consume(const T* target) {
126  return ::__atomic_load_n(target, __ATOMIC_CONSUME);
127 }
128 
134 template <typename T>
135 inline void atomic_store_seq_cst(T* target, T value) {
136  ::__atomic_store_n(target, value, __ATOMIC_SEQ_CST);
137 }
138 
144 template <typename T>
145 inline void atomic_store_release(T* target, T value) {
146  ::__atomic_store_n(target, value, __ATOMIC_RELEASE);
147 }
148 
149 } // namespace assorted
150 } // namespace foedus
151 
152 #endif // FOEDUS_ASSORTED_ATOMIC_FENCES_HPP_
void atomic_store_seq_cst(T *target, T value)
Atomic store with a seq_cst barrier for raw primitive types rather than std::atomic.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
T atomic_load_acquire(const T *target)
Atomic load with an acquire barrier for raw primitive types rather than std::atomic.
T atomic_load_consume(const T *target)
Atomic load with a consume barrier for raw primitive types rather than std::atomic.
void atomic_store_release(T *target, T value)
Atomic store with a release barrier for raw primitive types rather than std::atomic.
T atomic_load_seq_cst(const T *target)
Atomic load with a seq_cst barrier for raw primitive types rather than std::atomic.
void memory_fence_consume()
Equivalent to std::atomic_thread_fence(std::memory_order_consume).
void memory_fence_acquire()
Equivalent to std::atomic_thread_fence(std::memory_order_acquire).
void memory_fence_seq_cst()
Equivalent to std::atomic_thread_fence(std::memory_order_seq_cst).
void memory_fence_release()
Equivalent to std::atomic_thread_fence(std::memory_order_release).
void memory_fence_acq_rel()
Equivalent to std::atomic_thread_fence(std::memory_order_acq_rel).