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