2 Copyright 2005-2011 Intel Corporation. All Rights Reserved.
4 This file is part of Threading Building Blocks.
6 Threading Building Blocks is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
10 Threading Building Blocks is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Threading Building Blocks; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 As a special exception, you may use this file as part of a free software
20 library without restriction. Specifically, if other files instantiate
21 templates or use macros or inline functions from this file, or you compile
22 this file and link it with other files to produce an executable, this
23 file does not by itself cause the resulting executable to be covered by
24 the GNU General Public License. This exception does not however
25 invalidate any other reasons why the executable file might be covered by
26 the GNU General Public License.
29 #ifndef __TBB_machine_H
30 #error Do not include this file directly; include tbb_machine.h instead
36 #define __TBB_WORDSIZE __SIZEOF_INT__
38 //for some unknown reason straight mapping does not work. At least on mingw
39 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
40 #define __TBB_BIG_ENDIAN 0
41 #elif __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
42 #define __TBB_BIG_ENDIAN 1
44 #error "This endiannes is not supported."
47 //As the port has absolutely no information about underlying hardware, the performance,
48 //most likely, will be sub-optimal, due to usage of full memory fence where a lightweight
50 #define __TBB_acquire_consistency_helper() __sync_synchronize()
51 #define __TBB_release_consistency_helper() __sync_synchronize()
52 #define __TBB_full_memory_fence() __sync_synchronize()
53 #define __TBB_control_consistency_helper() __sync_synchronize()
56 #define __MACHINE_DECL_ATOMICS(S,T) \
57 inline T __TBB_generic_gcc_cmpswp##S(volatile void *ptr, T value, T comparand ) { \
58 return __sync_val_compare_and_swap(reinterpret_cast<volatile T *>(ptr),comparand,value); \
61 __MACHINE_DECL_ATOMICS(1,int8_t)
62 __MACHINE_DECL_ATOMICS(2,int16_t)
63 __MACHINE_DECL_ATOMICS(4,int32_t)
64 __MACHINE_DECL_ATOMICS(8,int64_t)
66 #define __TBB_CompareAndSwap1(P,V,C) __TBB_generic_gcc_cmpswp1(P,V,C)
67 #define __TBB_CompareAndSwap2(P,V,C) __TBB_generic_gcc_cmpswp2(P,V,C)
68 #define __TBB_CompareAndSwap4(P,V,C) __TBB_generic_gcc_cmpswp4(P,V,C)
69 #define __TBB_CompareAndSwap8(P,V,C) __TBB_generic_gcc_cmpswp8(P,V,C)
71 #if (__TBB_WORDSIZE==4)
72 #define __TBB_CompareAndSwapW(P,V,C) __TBB_CompareAndSwap4(P,V,C)
73 #elif (__TBB_WORDSIZE==8)
74 #define __TBB_CompareAndSwapW(P,V,C) __TBB_CompareAndSwap8(P,V,C)
76 #error "Unsupported word size."