Merge from subtype.
[cacao.git] / src / threads / atomic.hpp
1 /* src/threads/atomic.hpp - atomic instructions
2
3    Copyright (C) 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _ATOMIC_HPP
27 #define _ATOMIC_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #ifdef __cplusplus
34
35 class Atomic {
36 public:
37         // Generic functions.
38         static uint32_t generic_compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
39         static uint64_t generic_compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
40         static void*    generic_compare_and_swap(volatile void** p, void* oldval, void* newval);
41         static void     generic_memory_barrier(void);
42
43         // Machine dependent functions.
44         static uint32_t compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
45         static uint64_t compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
46         static void*    compare_and_swap(volatile void** p, void* oldval, void* newval);
47         static void     memory_barrier(void);
48         static void     write_memory_barrier(void);
49         static void     instruction_barrier(void);
50 };
51
52 // Include machine dependent implementation.
53 #include "md-atomic.hpp"
54
55 #else
56
57 // Legacy C interface.
58
59 uint32_t Atomic_compare_and_swap_32(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
60 uint64_t Atomic_compare_and_swap_64(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
61 void*    Atomic_compare_and_swap_ptr(volatile void** p, void* oldval, void* newval);
62 void     Atomic_memory_barrier(void);
63 void     Atomic_write_memory_barrier(void);
64 void     Atomic_instruction_barrier(void);
65
66 #endif
67
68 #endif // _ATOMIC_HPP
69
70
71 /*
72  * These are local overrides for various environment variables in Emacs.
73  * Please do not remove this and leave it at the end of the file, where
74  * Emacs will automagically detect them.
75  * ---------------------------------------------------------------------
76  * Local variables:
77  * mode: c++
78  * indent-tabs-mode: t
79  * c-basic-offset: 4
80  * tab-width: 4
81  * End:
82  * vim:noexpandtab:sw=4:ts=4:
83  */