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.
39 * A generic atomic compare and swap for 32-bit integer values. This
40 * function is using a mutex to provide atomicity.
42 * @param p Pointer to memory address.
43 * @param oldval Old value to be expected.
44 * @param newval New value to be stored.
46 * @return value of the memory location before the store
48 uint32_t generic_compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval)
54 // Do the compare-and-swap.
68 * A generic atomic compare and swap for 64-bit integer values. This
69 * function is using a mutex to provide atomicity.
71 * @param p Pointer to memory address.
72 * @param oldval Old value to be expected.
73 * @param newval New value to be stored.
75 * @return value of the memory location before the store
77 uint64_t generic_compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval)
83 // Do the compare-and-swap.
97 * A generic atomic compare and swap for pointer values. This
98 * function is using a mutex to provide atomicity.
100 * @param p Pointer to memory address.
101 * @param oldval Old value to be expected.
102 * @param newval New value to be stored.
104 * @return value of the memory location before the store
106 void* generic_compare_and_swap(volatile void** p, void* oldval, void* newval)
112 // Do the compare-and-swap.
116 if (oldval == result)
126 * A generic memory barrier. This function is using a mutex to
129 void generic_memory_barrier(void)
137 // Legacy C interface.
140 uint32_t Atomic_compare_and_swap_32(uint32_t *p, uint32_t oldval, uint32_t newval) { return Atomic::compare_and_swap(p, oldval, newval); }
141 uint64_t Atomic_compare_and_swap_64(uint64_t *p, uint64_t oldval, uint64_t newval) { return Atomic::compare_and_swap(p, oldval, newval); }
142 void* Atomic_compare_and_swap_ptr(void** p, void* oldval, void* newval) { return Atomic::compare_and_swap(p, oldval, newval); }
143 void Atomic_memory_barrier(void) { Atomic::memory_barrier(); }
144 void Atomic_write_memory_barrier(void) { Atomic::write_memory_barrier(); }
145 void Atomic_instruction_barrier(void) { Atomic::instruction_barrier(); }
150 * These are local overrides for various environment variables in Emacs.
151 * Please do not remove this and leave it at the end of the file, where
152 * Emacs will automagically detect them.
153 * ---------------------------------------------------------------------
156 * indent-tabs-mode: t
160 * vim:noexpandtab:sw=4:ts=4: