annotate bqvec/src/Barrier.cpp @ 372:af71cbdab621 tip

Update bqvec code
author Chris Cannam
date Tue, 19 Nov 2019 10:13:32 +0000
parents
children
rev   line source
Chris@372 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@372 2
Chris@372 3 /*
Chris@372 4 bqvec
Chris@372 5
Chris@372 6 A small library for vector arithmetic and allocation in C++ using
Chris@372 7 raw C pointer arrays.
Chris@372 8
Chris@372 9 Copyright 2007-2018 Particular Programs Ltd.
Chris@372 10
Chris@372 11 Permission is hereby granted, free of charge, to any person
Chris@372 12 obtaining a copy of this software and associated documentation
Chris@372 13 files (the "Software"), to deal in the Software without
Chris@372 14 restriction, including without limitation the rights to use, copy,
Chris@372 15 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@372 16 of the Software, and to permit persons to whom the Software is
Chris@372 17 furnished to do so, subject to the following conditions:
Chris@372 18
Chris@372 19 The above copyright notice and this permission notice shall be
Chris@372 20 included in all copies or substantial portions of the Software.
Chris@372 21
Chris@372 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@372 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@372 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@372 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@372 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@372 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@372 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@372 29
Chris@372 30 Except as contained in this notice, the names of Chris Cannam and
Chris@372 31 Particular Programs Ltd shall not be used in advertising or
Chris@372 32 otherwise to promote the sale, use or other dealings in this
Chris@372 33 Software without prior written authorization.
Chris@372 34 */
Chris@372 35
Chris@372 36 #include "Barrier.h"
Chris@372 37
Chris@372 38 #if defined __APPLE__
Chris@372 39 #if !defined __MAC_10_12
Chris@372 40 #include <libkern/OSAtomic.h>
Chris@372 41 #endif
Chris@372 42 #endif
Chris@372 43 #if defined _WIN32 && defined _MSC_VER
Chris@372 44 #include <Windows.h>
Chris@372 45 #endif
Chris@372 46
Chris@372 47 namespace breakfastquay {
Chris@372 48
Chris@372 49 void system_memorybarrier()
Chris@372 50 {
Chris@372 51 #if defined __APPLE__
Chris@372 52
Chris@372 53 #if defined __MAC_10_12
Chris@372 54 __sync_synchronize();
Chris@372 55 #else
Chris@372 56 OSMemoryBarrier();
Chris@372 57 #endif
Chris@372 58
Chris@372 59 #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
Chris@372 60
Chris@372 61 __sync_synchronize();
Chris@372 62
Chris@372 63 #elif defined _WIN32
Chris@372 64
Chris@372 65 #if defined _MSC_VER
Chris@372 66 MemoryBarrier();
Chris@372 67 #else /* (mingw) */
Chris@372 68 LONG Barrier = 0;
Chris@372 69 __asm__ __volatile__("xchgl %%eax,%0 "
Chris@372 70 : "=r" (Barrier));
Chris@372 71 #endif
Chris@372 72
Chris@372 73 #else
Chris@372 74 #warning "No memory barrier defined"
Chris@372 75 #endif
Chris@372 76
Chris@372 77 }
Chris@372 78
Chris@372 79 }
Chris@372 80