Fix mysterious unremovable file part 2 ?
[cacao.git] / src / threads / posix / generic-primitives.h
1 /* src/threads/native/generic-primitives.h - machine independent atomic
2                                              operations
3
4    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
5    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
6    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
7    J. Wenninger, Institut f. Computersprachen - TU Wien
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24    02110-1301, USA.
25
26    Contact: cacao@cacaojvm.org
27
28    Authors: Christian Thalinger
29             Anton Ertl
30
31    Changes: 
32
33
34 */
35
36
37 #ifndef _MACHINE_INSTR_H
38 #define _MACHINE_INSTR_H
39
40 #include <pthread.h>
41
42 #include "threads/mutex.h"
43
44
45 extern mutex_t _cas_lock;
46 extern mutex_t _mb_lock;
47
48
49 static inline long compare_and_swap(volatile long *p, long oldval, long newval)
50 {
51   long ret;
52
53   mutex_lock(&_cas_lock);
54
55   /* do the compare-and-swap */
56
57   ret = *p;
58
59   if (oldval == ret)
60     *p = newval;
61
62   mutex_unlock(&_cas_lock);
63
64   return ret;
65 }
66
67
68 #define MEMORY_BARRIER()                  (mutex_lock(&_mb_lock), \
69                                            mutex_unlock(&_mb_lock))
70 #define STORE_ORDER_BARRIER()             MEMORY_BARRIER()
71 #define MEMORY_BARRIER_AFTER_ATOMIC()     /* nothing */
72
73 #endif /* _MACHINE_INSTR_H */
74
75
76 /*
77  * These are local overrides for various environment variables in Emacs.
78  * Please do not remove this and leave it at the end of the file, where
79  * Emacs will automagically detect them.
80  * ---------------------------------------------------------------------
81  * Local variables:
82  * mode: c
83  * indent-tabs-mode: t
84  * c-basic-offset: 4
85  * tab-width: 4
86  * End:
87  */