1 /* src/threads/atomic.hpp - atomic instructions
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 // Machine dependent functions.
37 uint32_t compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
38 uint64_t compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
40 void memory_barrier(void);
41 void write_memory_barrier(void);
42 void instruction_barrier(void);
48 uint32_t generic_compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
49 uint64_t generic_compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
50 void* generic_compare_and_swap(volatile void** p, void* oldval, void* newval);
51 void generic_memory_barrier(void);
55 // Include machine dependent implementation.
56 #include "md-atomic.hpp"
60 struct CAS_32_functor {
61 typedef uint32_t value_type;
62 static value_type compare_and_swap(value_type *p, value_type o, value_type n) {
63 return Atomic_md::compare_and_swap(p, o, n);
67 struct CAS_64_functor {
68 typedef uint64_t value_type;
69 static value_type compare_and_swap(value_type *p, value_type o, value_type n) {
70 return Atomic_md::compare_and_swap(p, o, n);
74 template<int N> class CAS_chooser;
75 template<> class CAS_chooser<4> {
77 typedef CAS_32_functor the_type;
79 template<> class CAS_chooser<8> {
81 typedef CAS_64_functor the_type;
84 template<class T> class CAS {
86 typedef typename CAS_chooser<sizeof(T)>::the_type S;
87 static T compare_and_swap(T *p, T o, T n) {
88 return (T) S::compare_and_swap((typename S::value_type*) p,
89 (typename S::value_type) o,
90 (typename S::value_type) n);
94 template<class T> T compare_and_swap(T *p, T o, T n) {
95 return CAS<T>::compare_and_swap(p, o, n);
98 inline void memory_barrier(void) { Atomic_md::memory_barrier(); }
99 inline void write_memory_barrier(void) { Atomic_md::write_memory_barrier(); }
100 inline void instruction_barrier(void) { Atomic_md::instruction_barrier(); }
105 // Legacy C interface.
107 uint32_t Atomic_compare_and_swap_32(uint32_t *p, uint32_t oldval, uint32_t newval);
108 uint64_t Atomic_compare_and_swap_64(uint64_t *p, uint64_t oldval, uint64_t newval);
109 void* Atomic_compare_and_swap_ptr(void** p, void* oldval, void* newval);
110 void Atomic_memory_barrier(void);
111 void Atomic_write_memory_barrier(void);
112 void Atomic_instruction_barrier(void);
116 #endif // _ATOMIC_HPP
120 * These are local overrides for various environment variables in Emacs.
121 * Please do not remove this and leave it at the end of the file, where
122 * Emacs will automagically detect them.
123 * ---------------------------------------------------------------------
126 * indent-tabs-mode: t
130 * vim:noexpandtab:sw=4:ts=4: