Chris@372: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@372: Chris@372: /* Chris@372: bqvec Chris@372: Chris@372: A small library for vector arithmetic and allocation in C++ using Chris@372: raw C pointer arrays. Chris@372: Chris@372: Copyright 2007-2018 Particular Programs Ltd. Chris@372: Chris@372: Permission is hereby granted, free of charge, to any person Chris@372: obtaining a copy of this software and associated documentation Chris@372: files (the "Software"), to deal in the Software without Chris@372: restriction, including without limitation the rights to use, copy, Chris@372: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@372: of the Software, and to permit persons to whom the Software is Chris@372: furnished to do so, subject to the following conditions: Chris@372: Chris@372: The above copyright notice and this permission notice shall be Chris@372: included in all copies or substantial portions of the Software. Chris@372: Chris@372: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@372: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@372: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@372: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@372: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@372: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@372: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@372: Chris@372: Except as contained in this notice, the names of Chris Cannam and Chris@372: Particular Programs Ltd shall not be used in advertising or Chris@372: otherwise to promote the sale, use or other dealings in this Chris@372: Software without prior written authorization. Chris@372: */ Chris@372: Chris@372: #include "Barrier.h" Chris@372: Chris@372: #if defined __APPLE__ Chris@372: #if !defined __MAC_10_12 Chris@372: #include Chris@372: #endif Chris@372: #endif Chris@372: #if defined _WIN32 && defined _MSC_VER Chris@372: #include Chris@372: #endif Chris@372: Chris@372: namespace breakfastquay { Chris@372: Chris@372: void system_memorybarrier() Chris@372: { Chris@372: #if defined __APPLE__ Chris@372: Chris@372: #if defined __MAC_10_12 Chris@372: __sync_synchronize(); Chris@372: #else Chris@372: OSMemoryBarrier(); Chris@372: #endif Chris@372: Chris@372: #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) Chris@372: Chris@372: __sync_synchronize(); Chris@372: Chris@372: #elif defined _WIN32 Chris@372: Chris@372: #if defined _MSC_VER Chris@372: MemoryBarrier(); Chris@372: #else /* (mingw) */ Chris@372: LONG Barrier = 0; Chris@372: __asm__ __volatile__("xchgl %%eax,%0 " Chris@372: : "=r" (Barrier)); Chris@372: #endif Chris@372: Chris@372: #else Chris@372: #warning "No memory barrier defined" Chris@372: #endif Chris@372: Chris@372: } Chris@372: Chris@372: } Chris@372: