GNU Radio 3.4.2 C++ API
memory_barrier.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 
00022 #ifndef INCLUDED_GCELL_MEMORY_BARRIER_H
00023 #define INCLUDED_GCELL_MEMORY_BARRIER_H
00024 
00025 /*
00026  * powerpc memory barriers
00027  *
00028  * The sync instruction guarantees that all memory accesses initiated
00029  * by this processor have been performed (with respect to all other
00030  * mechanisms that access memory).  The eieio instruction is a barrier
00031  * providing an ordering (separately) for (a) cacheable stores and (b)
00032  * loads and stores to non-cacheable memory (e.g. I/O devices).
00033  *
00034  * smp_mb() prevents loads and stores being reordered across this point.
00035  * smp_rmb() prevents loads being reordered across this point.
00036  * smp_wmb() prevents stores being reordered across this point.
00037  *
00038  * We have to use the sync instructions for smp_mb(), since lwsync
00039  * doesn't order loads with respect to previous stores.  Lwsync is
00040  * fine for smp_rmb(), though.  For smp_wmb(), we use eieio since it
00041  * is only used to order updates to system memory.
00042  *
00043  * For details, see "PowerPC Virtual Environment Architecture, Book
00044  * II".  Especially Chapter 1, "Storage Model" and Chapter 3, "Storage
00045  * Control Instructions." (site:ibm.com)
00046  */
00047 
00048 static inline void smp_mb(void)
00049 {
00050   __asm__ volatile ("sync" : : : "memory");
00051 }
00052 
00053 static inline void smp_rmb(void)
00054 {
00055   __asm__ volatile ("lwsync" : : : "memory");
00056 }
00057 
00058 static inline void smp_wmb(void)
00059 {
00060   __asm__ volatile ("eieio" : : : "memory");
00061 }
00062 
00063 
00064 #endif /* INCLUDED_GCELL_MEMORY_BARRIER_H */