1 /* src/threads/atomic.cpp - 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
30 #include "threads/atomic.hpp"
31 #include "threads/mutex.hpp"
33 // Gobal mutex for generic atomic instructions.
38 * A generic atomic compare and swap for 32-bit integer values. This
39 * function is using a mutex to provide atomicity.
41 * @param p Pointer to memory address.
42 * @param oldval Old value to be expected.
43 * @param newval New value to be stored.
45 * @return value of the memory location before the store
47 uint32_t Atomic::generic_compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval)
53 // Do the compare-and-swap.
67 * A generic atomic compare and swap for 64-bit integer values. This
68 * function is using a mutex to provide atomicity.
70 * @param p Pointer to memory address.
71 * @param oldval Old value to be expected.
72 * @param newval New value to be stored.
74 * @return value of the memory location before the store
76 uint64_t Atomic::generic_compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval)
82 // Do the compare-and-swap.
96 * A generic atomic compare and swap for pointer values. This
97 * function is using a mutex to provide atomicity.
99 * @param p Pointer to memory address.
100 * @param oldval Old value to be expected.
101 * @param newval New value to be stored.
103 * @return value of the memory location before the store
105 void* Atomic::generic_compare_and_swap(volatile void** p, void* oldval, void* newval)
111 // Do the compare-and-swap.
115 if (oldval == result)
125 * A generic memory barrier. This function is using a mutex to
128 void Atomic::generic_memory_barrier(void)
135 // Legacy C interface.
138 uint32_t Atomic_compare_and_swap_32(volatile uint32_t *p, uint32_t oldval, uint32_t newval) { return Atomic::compare_and_swap(p, oldval, newval); }
139 uint64_t Atomic_compare_and_swap_64(volatile uint64_t *p, uint64_t oldval, uint64_t newval) { return Atomic::compare_and_swap(p, oldval, newval); }
140 void* Atomic_compare_and_swap_ptr(volatile void** p, void* oldval, void* newval) { return Atomic::compare_and_swap(p, oldval, newval); }
141 void Atomic_memory_barrier(void) { Atomic::memory_barrier(); }
142 void Atomic_write_memory_barrier(void) { Atomic::write_memory_barrier(); }
143 void Atomic_instruction_barrier(void) { Atomic::instruction_barrier(); }
148 * These are local overrides for various environment variables in Emacs.
149 * Please do not remove this and leave it at the end of the file, where
150 * Emacs will automagically detect them.
151 * ---------------------------------------------------------------------
154 * indent-tabs-mode: t
158 * vim:noexpandtab:sw=4:ts=4: