Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / include / gcell / memory_barrier.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef INCLUDED_GCELL_MEMORY_BARRIER_H
23 #define INCLUDED_GCELL_MEMORY_BARRIER_H
24
25 /*
26  * powerpc memory barriers
27  *
28  * The sync instruction guarantees that all memory accesses initiated
29  * by this processor have been performed (with respect to all other
30  * mechanisms that access memory).  The eieio instruction is a barrier
31  * providing an ordering (separately) for (a) cacheable stores and (b)
32  * loads and stores to non-cacheable memory (e.g. I/O devices).
33  *
34  * smp_mb() prevents loads and stores being reordered across this point.
35  * smp_rmb() prevents loads being reordered across this point.
36  * smp_wmb() prevents stores being reordered across this point.
37  *
38  * We have to use the sync instructions for smp_mb(), since lwsync
39  * doesn't order loads with respect to previous stores.  Lwsync is
40  * fine for smp_rmb(), though.  For smp_wmb(), we use eieio since it
41  * is only used to order updates to system memory.
42  *
43  * For details, see "PowerPC Virtual Environment Architecture, Book
44  * II".  Especially Chapter 1, "Storage Model" and Chapter 3, "Storage
45  * Control Instructions." (site:ibm.com)
46  */
47
48 static inline void smp_mb(void)
49 {
50   __asm__ volatile ("sync" : : : "memory");
51 }
52
53 static inline void smp_rmb(void)
54 {
55   __asm__ volatile ("lwsync" : : : "memory");
56 }
57
58 static inline void smp_wmb(void)
59 {
60   __asm__ volatile ("eieio" : : : "memory");
61 }
62
63
64 #endif /* INCLUDED_GCELL_MEMORY_BARRIER_H */