├── lib ├── x64 │ ├── tbb.lib │ └── mono.lib └── Win32 │ ├── tbb.lib │ └── mono.lib ├── PatchLibrary32.dll ├── PatchLibrary64.dll ├── PatchLibraryBridge32.exe ├── PatchLibraryBridge64.exe ├── TestScene ├── Assets │ ├── Test.unity │ ├── Plugins │ │ ├── x86 │ │ │ ├── tbb.dll │ │ │ ├── CppScript.dll │ │ │ ├── CppScript.pdb │ │ │ ├── tbb.dll.meta │ │ │ ├── CppScript.dll.meta │ │ │ ├── CppScript.pdb.meta │ │ │ ├── CppScriptCore.dll │ │ │ ├── CppScriptCore.pdb │ │ │ ├── CppScriptCore.dll.meta │ │ │ └── CppScriptCore.pdb.meta │ │ ├── x86_64 │ │ │ ├── tbb.dll │ │ │ ├── CppScript.dll │ │ │ ├── CppScript.pdb │ │ │ ├── tbb.dll.meta │ │ │ ├── CppScript.dll.meta │ │ │ ├── CppScript.pdb.meta │ │ │ ├── CppScriptCore.dll │ │ │ ├── CppScriptCore.pdb │ │ │ ├── CppScriptCore.dll.meta │ │ │ └── CppScriptCore.pdb.meta │ │ ├── x86.meta │ │ └── x86_64.meta │ ├── CppScripts │ │ ├── CppBehaviour.h.meta │ │ ├── CubeDrawer.cpp.meta │ │ ├── CubeDrawer.h.meta │ │ ├── AsyncBehaviour.cpp.meta │ │ ├── AsyncBehaviour.h.meta │ │ ├── CppBehaviour.cpp.meta │ │ ├── TestCppBehaviour.cpp.meta │ │ ├── CppBehaviour.cpp │ │ ├── TestCppBehaviour.cs.meta │ │ ├── CppBehaviour.h │ │ ├── CubeDrawer.h │ │ ├── TestAsyncBehaviour.cpp │ │ ├── CubeDrawer.cpp │ │ ├── AsyncBehaviour.h │ │ ├── AsyncBehaviour.cpp │ │ ├── TestCppBehaviour.cs │ │ └── TestCppBehaviour.cpp │ ├── Plugins.meta │ ├── Scripts.meta │ ├── CppScripts.meta │ └── Test.unity.meta └── build.bat ├── cpsInternal.h ├── include ├── tbb │ ├── index.html │ ├── compat │ │ ├── thread │ │ └── ppl.h │ ├── aligned_space.h │ ├── null_mutex.h │ ├── null_rw_mutex.h │ ├── tbbmalloc_proxy.h │ ├── machine │ │ ├── mic_common.h │ │ ├── linux_common.h │ │ ├── windows_api.h │ │ ├── ibm_aix51.h │ │ ├── gcc_ia32_common.h │ │ ├── xbox360_ppc.h │ │ ├── gcc_itsx.h │ │ ├── windows_intel64.h │ │ ├── macos_common.h │ │ ├── linux_intel64.h │ │ ├── windows_ia32.h │ │ ├── gcc_generic.h │ │ └── msvc_armv7.h │ ├── combinable.h │ ├── internal │ │ ├── _range_iterator.h │ │ ├── _tbb_windef.h │ │ ├── _tbb_strings.h │ │ ├── _mutex_padding.h │ │ └── _x86_eliding_mutex_impl.h │ ├── tbb.h │ ├── parallel_for_each.h │ ├── blocked_range2d.h │ ├── queuing_mutex.h │ ├── critical_section.h │ ├── blocked_range3d.h │ ├── tick_count.h │ ├── cache_aligned_allocator.h │ ├── queuing_rw_mutex.h │ ├── parallel_while.h │ ├── runtime_loader.h │ ├── task_group.h │ └── blocked_range.h └── serial │ └── tbb │ └── tbb_annotate.h ├── README.md ├── cpsUtils.h └── CppScript.sln /lib/x64/tbb.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/lib/x64/tbb.lib -------------------------------------------------------------------------------- /lib/Win32/tbb.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/lib/Win32/tbb.lib -------------------------------------------------------------------------------- /lib/x64/mono.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/lib/x64/mono.lib -------------------------------------------------------------------------------- /PatchLibrary32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/PatchLibrary32.dll -------------------------------------------------------------------------------- /PatchLibrary64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/PatchLibrary64.dll -------------------------------------------------------------------------------- /lib/Win32/mono.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/lib/Win32/mono.lib -------------------------------------------------------------------------------- /PatchLibraryBridge32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/PatchLibraryBridge32.exe -------------------------------------------------------------------------------- /PatchLibraryBridge64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/PatchLibraryBridge64.exe -------------------------------------------------------------------------------- /TestScene/Assets/Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Test.unity -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/tbb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86/tbb.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/tbb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86_64/tbb.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScript.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86/CppScript.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScript.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86/CppScript.pdb -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/tbb.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6af67a456ac6c8740af759e0ae0abd55 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScript.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86_64/CppScript.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScript.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86_64/CppScript.pdb -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CppBehaviour.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3b23346e39b352489ebe336f15c5db1 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CubeDrawer.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 582d1b4148df18043b7545ceadad3b43 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CubeDrawer.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84ed56dc3cb79664e868c3f19049757a 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScript.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 415be58e45bbedf418bbcd60c2beb27f 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScript.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cd12d14f9b23b24796d46de2677b6ab 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScriptCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86/CppScriptCore.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScriptCore.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86/CppScriptCore.pdb -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/tbb.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25bf3485266a6844dbb9b601dee916e0 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/build.bat: -------------------------------------------------------------------------------- 1 | call "%VS120COMNTOOLS%vsvars32.bat" 2 | cd .. 3 | msbuild CppScript.sln /m /p:Configuration=Release;Platform=Win32 4 | pause 5 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/AsyncBehaviour.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e138df92dbd118a46b83c22ef78307a9 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/AsyncBehaviour.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c171a3dd79c4c4f4d97f172639627076 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CppBehaviour.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b873a2d9a831834a97b0be7fcea8e80 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be0bee9e0ad8d71459870b065df9e580 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScriptCore.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b959057822e58954dbf2ef3917a7cfc4 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86/CppScriptCore.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cef7d72ee835f94faaaf2568bf49f8c 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScript.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c93c89bf0d418764fbb1709631cb2428 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScript.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1da91631a2e0c624ebe0351e4316f327 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScriptCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86_64/CppScriptCore.dll -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScriptCore.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-saint/UnityCppScript/HEAD/TestScene/Assets/Plugins/x86_64/CppScriptCore.pdb -------------------------------------------------------------------------------- /TestScene/Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 218840807a7083247ba000701d8d61a5 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a1fccd6351c5ed4abfae82a8244abfa 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/TestCppBehaviour.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b7aeaee281dc8a4f850d91c3e2a14c9 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScriptCore.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d656359176a1d3a40aeb5bda0f205b5a 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64/CppScriptCore.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a1ff93e6d37a664586c59db5e4c042d 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /TestScene/Assets/Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f011bc238eb3b7d45a2a3194c3d5f29b 3 | DefaultImporter: 4 | userData: 5 | assetBundleName: 6 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CppBehaviour.cpp: -------------------------------------------------------------------------------- 1 | #include "CppBehaviour.h" 2 | 3 | #define cpsCurrentClass CppBehaviour 4 | cpsExportClass() 5 | #undef cpsCurrentClass 6 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffdaa3adf01370240a8d07f6135a030d 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | assetBundleName: 7 | -------------------------------------------------------------------------------- /TestScene/Assets/Plugins/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9eb3439b3b3777f4e8fa3cfe1f63a97f 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | assetBundleName: 7 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/TestCppBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71b025b0566e05b4394a3d6fc636e570 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /cpsInternal.h: -------------------------------------------------------------------------------- 1 | #ifndef cpsInternal_h 2 | #define cpsInternal_h 3 | 4 | #define cpsBuildDLL 5 | #define cpsAPI __declspec(dllexport) 6 | 7 | #if defined(_WIN32) && !defined(cpsWithoutDbgHelp) 8 | #define _CRT_SECURE_NO_WARNINGS 9 | #include 10 | #include 11 | #pragma comment(lib, "dbghelp.lib") 12 | #endif 13 | 14 | #include "monoAPI.h" 15 | 16 | #endif // cpsInternal_h 17 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CppBehaviour.h: -------------------------------------------------------------------------------- 1 | #ifndef CppBehaviour_h 2 | #define CppBehaviour_h 3 | 4 | #include "cpsBinder.h" 5 | #include "cpsUtils.h" 6 | #include "cpsUnityEngine.h" 7 | using namespace UnityEngine; 8 | 9 | 10 | class CppBehaviour : public Behaviour 11 | { 12 | typedef Behaviour super; 13 | public: 14 | CppBehaviour(cpsObject o=nullptr) : super(o) {} 15 | virtual ~CppBehaviour() {} 16 | }; 17 | 18 | #endif // CppBehaviour_h 19 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CubeDrawer.h: -------------------------------------------------------------------------------- 1 | #ifndef CubeDrawer_h 2 | #define CubeDrawer_h 3 | #include "CppBehaviour.h" 4 | #include "AsyncBehaviour.h" 5 | 6 | struct CubeInstanceData 7 | { 8 | Vector3 position; 9 | float scale; 10 | Vector4 diffuse; 11 | Vector4 emission; 12 | }; 13 | typedef std::vector CubeCont; 14 | 15 | 16 | class CubeDrawer : public CppBehaviour 17 | { 18 | typedef CppBehaviour super; 19 | public: 20 | static CubeDrawer* getInstance(); 21 | 22 | CubeDrawer(cpsObject o); 23 | ~CubeDrawer(); 24 | void OnPreRender(); 25 | void OnPostRender(); 26 | 27 | CubeCont& getInstanceBuffer(); 28 | 29 | private: 30 | static CubeDrawer *s_inst; 31 | ComputeBuffer m_buffer; 32 | std::vector m_data; 33 | }; 34 | 35 | #endif // CubeDrawer_h 36 | -------------------------------------------------------------------------------- /include/tbb/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Overview

5 | Include files for Intel® Threading Building Blocks classes and functions. 6 | 7 |
Click here to see all files in the directory. 8 | 9 |

Directories

10 |
11 |
compat 12 |
Include files for source level compatibility with other frameworks. 13 |
internal 14 |
Include files with implementation details; not for direct use. 15 |
machine 16 |
Include files for low-level architecture specific functionality; not for direct use. 17 |
18 | 19 |
20 | Up to parent directory 21 |

22 | Copyright © 2005-2014 Intel Corporation. All Rights Reserved. 23 |

24 | Intel is a registered trademark or trademark of Intel Corporation 25 | or its subsidiaries in the United States and other countries. 26 |

27 | * Other names and brands may be claimed as the property of others. 28 | 29 | 30 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/TestAsyncBehaviour.cpp: -------------------------------------------------------------------------------- 1 | #include "AsyncBehaviour.h" 2 | #include "CubeDrawer.h" 3 | 4 | 5 | class TestAsyncBehaviour : public AsyncBehaviour 6 | { 7 | typedef AsyncBehaviour super; 8 | public: 9 | TestAsyncBehaviour(cpsObject o); 10 | virtual ~TestAsyncBehaviour(); 11 | 12 | void BeforeAsyncUpdate(); 13 | void AsyncUpdate(); 14 | void AfterAsyncUpdate(); 15 | 16 | private: 17 | Transform trans; 18 | }; 19 | 20 | #define cpsCurrentClass TestAsyncBehaviour 21 | cpsExportClass() 22 | cpsExportMethod(BeforeAsyncUpdate) 23 | cpsExportMethod(AsyncUpdate) 24 | cpsExportMethod(AfterAsyncUpdate) 25 | #undef cpsCurrentClass 26 | 27 | 28 | 29 | 30 | TestAsyncBehaviour::TestAsyncBehaviour(cpsObject o) 31 | : super(o) 32 | { 33 | trans = GetComponent(); 34 | } 35 | 36 | TestAsyncBehaviour::~TestAsyncBehaviour() 37 | { 38 | } 39 | 40 | void TestAsyncBehaviour::BeforeAsyncUpdate() 41 | { 42 | } 43 | 44 | void TestAsyncBehaviour::AsyncUpdate() 45 | { 46 | } 47 | 48 | void TestAsyncBehaviour::AfterAsyncUpdate() 49 | { 50 | } 51 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/CubeDrawer.cpp: -------------------------------------------------------------------------------- 1 | #include "CubeDrawer.h" 2 | 3 | #define cpsCurrentClass CubeDrawer 4 | cpsExportClass() 5 | cpsExportMethod(OnPreRender) 6 | cpsExportMethod(OnPostRender) 7 | #undef cpsCurrentClass 8 | 9 | 10 | CubeDrawer* CubeDrawer::s_inst; 11 | 12 | 13 | CubeDrawer* CubeDrawer::getInstance() 14 | { 15 | return s_inst; 16 | } 17 | 18 | CubeDrawer::CubeDrawer(cpsObject o) 19 | : super(o) 20 | { 21 | if (s_inst != nullptr) { 22 | cpsDebugPrint("CubeDrawer::s_inst is not null!\n"); 23 | } 24 | s_inst = this; 25 | 26 | m_data.reserve(1024 * 16); 27 | findField("instance_buffer").getValue(*this, m_buffer); 28 | } 29 | 30 | CubeDrawer::~CubeDrawer() 31 | { 32 | if (s_inst != this) { 33 | cpsDebugPrint("CubeDrawer::s_inst is not this!\n"); 34 | } 35 | s_inst = nullptr; 36 | } 37 | 38 | void CubeDrawer::OnPreRender() 39 | { 40 | // todo 41 | //m_buffer.SetData(m_data); 42 | m_data.clear(); 43 | 44 | } 45 | 46 | void CubeDrawer::OnPostRender() 47 | { 48 | } 49 | 50 | CubeCont& CubeDrawer::getInstanceBuffer() 51 | { 52 | return m_data; 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UnityCppScript 2 | ============== 3 | 4 | C++ から Unity の C# の API を呼べるようにするプラグイン兼ライブラリです。 5 | C++ スクリプト的に使いたい場合や、既存の C++ のライブラリと Unity のやりとりを簡単にできるようにすることを目的としています。 6 | 7 | Mono の API を叩いて C# のアセンブリにアクセスすることで実現しています。 8 | 詳細: http://i-saint.hatenablog.com/entry/2014/10/24/190807 9 | 注意点として、Mono を経由する処理は非常に遅く、Unity の C# の API を呼ぶ処理は普通に C# で実行したのと同等の速度になります。 10 | それ以外の純粋なスクリプトの処理内容が相応に重い場合でないと速度的にはあまり効果はありません。 11 | 12 | 13 | This plugin library enables calling Unity C# API from C++ code. 14 | Use of C++ as a script, and the communication with existing C++ library can be done easily. 15 | 16 | This library is implemented by calling Mono's API to access C# assembly directly. 17 | Details: http://i-saint.hatenablog.com/entry/2014/10/24/190807 18 | Note that since processing through Mono is very slow, the speed of calling Unity C# API from C++ is about the same as simply calling from C#. Other than that, if it's not very heavy on pure script processing, it won't be very effective on performance. 19 | 20 | 21 | Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. 22 | 23 | -------------------------------------------------------------------------------- /cpsUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef cpsUtils_h 2 | #define cpsUtils_h 3 | 4 | #include "cpsFoundation.h" 5 | 6 | #define cpsMaxSymName 2500 7 | 8 | cpsAPI void cpsDumpClassStructure(cpsClass cpsc); 9 | cpsAPI void cpsAddressToSymbolName(void *addr, char *out_name, size_t out_len); 10 | cpsAPI void cpsDebugPrint(const char *format, ...); 11 | 12 | 13 | class cpsAPI cpsCachedImage : public cpsImage 14 | { 15 | public: 16 | cpsCachedImage(); 17 | ~cpsCachedImage(); 18 | void operator=(const cpsImage &v) { mimage = v.mimage; } 19 | }; 20 | 21 | class cpsAPI cpsCachedClass : public cpsClass 22 | { 23 | public: 24 | cpsCachedClass(); 25 | ~cpsCachedClass(); 26 | void operator=(const cpsClass &v) { mclass = v.mclass; } 27 | }; 28 | 29 | class cpsAPI cpsCachedField : public cpsField 30 | { 31 | public: 32 | cpsCachedField(); 33 | ~cpsCachedField(); 34 | void operator=(const cpsField &v) { mfield = v.mfield; } 35 | }; 36 | 37 | class cpsAPI cpsCachedMethod : public cpsMethod 38 | { 39 | public: 40 | cpsCachedMethod(); 41 | ~cpsCachedMethod(); 42 | void operator=(const cpsMethod &v) { mmethod = v.mmethod; } 43 | }; 44 | 45 | class cpsAPI cpsCachedProperty : public cpsProperty 46 | { 47 | public: 48 | cpsCachedProperty(); 49 | ~cpsCachedProperty(); 50 | void operator=(const cpsProperty &v) { mproperty = v.mproperty; } 51 | }; 52 | 53 | #endif // cpsUtils_h 54 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/AsyncBehaviour.h: -------------------------------------------------------------------------------- 1 | #ifndef AsyncBehaviour_h 2 | #define AsyncBehaviour_h 3 | #include "CppBehaviour.h" 4 | #include 5 | 6 | class AsyncBehaviour; 7 | typedef uint32_t EntityHandle; 8 | 9 | class AsyncBehaviourManager : public CppBehaviour 10 | { 11 | typedef CppBehaviour super; 12 | public: 13 | typedef std::vector EntityCont; 14 | typedef std::vector HandleCont; 15 | 16 | static AsyncBehaviourManager* getInstance(); 17 | EntityHandle addEntity(AsyncBehaviour *e); 18 | void eraseEntity(EntityHandle h); // 死亡を他 entity が察知できるようにするため、1 frame 遅延させる 19 | void eraseEntityImmediate(EntityHandle h); // 1 frame の遅延抜きに直ちに消去する 20 | 21 | AsyncBehaviourManager(cpsObject o) : super(o) {} 22 | void Awake(); 23 | void OnDestroy(); 24 | void Update(); 25 | 26 | private: 27 | EntityCont m_entities; 28 | HandleCont m_all; 29 | HandleCont m_vacants; 30 | HandleCont m_dead; 31 | HandleCont m_dead_prev; 32 | }; 33 | 34 | 35 | class AsyncBehaviour : public CppBehaviour 36 | { 37 | typedef CppBehaviour super; 38 | friend class AsyncBehaviourManager; 39 | public: 40 | AsyncBehaviour(cpsObject o) : super(o) {} 41 | virtual void BeforeAsyncUpdate(); 42 | virtual void AsyncUpdate(); 43 | virtual void AfterAsyncUpdate(); 44 | 45 | EntityHandle getHandle() const { return m_handle; } 46 | 47 | private: 48 | EntityHandle m_handle; 49 | }; 50 | 51 | #endif // AsyncBehaviour_h 52 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/AsyncBehaviour.cpp: -------------------------------------------------------------------------------- 1 | #include "AsyncBehaviour.h" 2 | #include "tbb/tbb.h" 3 | 4 | #define cpsCurrentClass AsyncBehaviourManager 5 | cpsExportSingletonClass() 6 | cpsExportMethod(Awake) 7 | cpsExportMethod(OnDestroy) 8 | cpsExportMethod(Update) 9 | #undef cpsCurrentClass 10 | 11 | #define cpsCurrentClass AsyncBehaviour 12 | cpsExportClass() 13 | cpsExportMethod(BeforeAsyncUpdate) 14 | cpsExportMethod(AsyncUpdate) 15 | cpsExportMethod(AfterAsyncUpdate) 16 | #undef cpsCurrentClass 17 | 18 | 19 | static AsyncBehaviourManager* s_instance; 20 | 21 | /*static*/ AsyncBehaviourManager* AsyncBehaviourManager::getInstance() 22 | { 23 | if (!s_instance) { 24 | s_instance = new AsyncBehaviourManager(nullptr); 25 | } 26 | return s_instance; 27 | } 28 | 29 | void AsyncBehaviourManager::Awake() 30 | { 31 | } 32 | 33 | void AsyncBehaviourManager::OnDestroy() 34 | { 35 | } 36 | 37 | void AsyncBehaviourManager::Update() 38 | { 39 | for (AsyncBehaviour *e : m_entities) { 40 | e->BeforeAsyncUpdate(); 41 | } 42 | 43 | typedef tbb::blocked_range range_t; 44 | tbb::parallel_for( 45 | range_t(size_t(0), m_entities.size(), 64), 46 | [&](const range_t &r){ 47 | for (size_t i = r.begin(); i < r.end(); ++i) { 48 | m_entities[i]->AsyncUpdate(); 49 | } 50 | }); 51 | 52 | for (AsyncBehaviour *e : m_entities) { 53 | e->AfterAsyncUpdate(); 54 | } 55 | } 56 | 57 | 58 | 59 | void AsyncBehaviour::BeforeAsyncUpdate() 60 | { 61 | } 62 | 63 | void AsyncBehaviour::AsyncUpdate() 64 | { 65 | } 66 | 67 | void AsyncBehaviour::AfterAsyncUpdate() 68 | { 69 | } 70 | -------------------------------------------------------------------------------- /include/serial/tbb/tbb_annotate.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_annotate_H 22 | #define __TBB_annotate_H 23 | 24 | // Macros used by the Intel(R) Parallel Advisor. 25 | #ifdef __TBB_NORMAL_EXECUTION 26 | #define ANNOTATE_SITE_BEGIN( site ) 27 | #define ANNOTATE_SITE_END( site ) 28 | #define ANNOTATE_TASK_BEGIN( task ) 29 | #define ANNOTATE_TASK_END( task ) 30 | #define ANNOTATE_LOCK_ACQUIRE( lock ) 31 | #define ANNOTATE_LOCK_RELEASE( lock ) 32 | #else 33 | #include 34 | #endif 35 | 36 | #endif /* __TBB_annotate_H */ 37 | -------------------------------------------------------------------------------- /include/tbb/compat/thread: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_thread_H 22 | #define __TBB_thread_H 23 | 24 | #include "../tbb_thread.h" 25 | 26 | #if TBB_IMPLEMENT_CPP0X 27 | 28 | namespace std { 29 | 30 | typedef tbb::tbb_thread thread; 31 | 32 | namespace this_thread { 33 | using tbb::this_tbb_thread::get_id; 34 | using tbb::this_tbb_thread::yield; 35 | 36 | inline void sleep_for(const tbb::tick_count::interval_t& rel_time) { 37 | tbb::internal::thread_sleep_v3( rel_time ); 38 | } 39 | 40 | } 41 | 42 | } 43 | 44 | #endif /* TBB_IMPLEMENT_CPP0X */ 45 | 46 | #endif /* __TBB_thread_H */ 47 | -------------------------------------------------------------------------------- /include/tbb/aligned_space.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_aligned_space_H 22 | #define __TBB_aligned_space_H 23 | 24 | #include "tbb_stddef.h" 25 | #include "tbb_machine.h" 26 | 27 | namespace tbb { 28 | 29 | //! Block of space aligned sufficiently to construct an array T with N elements. 30 | /** The elements are not constructed or destroyed by this class. 31 | @ingroup memory_allocation */ 32 | template 33 | class aligned_space { 34 | private: 35 | typedef __TBB_TypeWithAlignmentAtLeastAsStrict(T) element_type; 36 | element_type array[(sizeof(T)*N+sizeof(element_type)-1)/sizeof(element_type)]; 37 | public: 38 | //! Pointer to beginning of array 39 | T* begin() {return internal::punned_cast(this);} 40 | 41 | //! Pointer to one past last element in array. 42 | T* end() {return begin()+N;} 43 | }; 44 | 45 | } // namespace tbb 46 | 47 | #endif /* __TBB_aligned_space_H */ 48 | -------------------------------------------------------------------------------- /CppScript.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppScriptCore", "CppScriptCore.vcxproj", "{45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppScript", "TestScene\CppScript.vcxproj", "{CFB36449-2482-411B-8082-86D0004DF9B7}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151} = {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Debug|x64 = Debug|x64 17 | Release|Win32 = Release|Win32 18 | Release|x64 = Release|x64 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Debug|Win32.Build.0 = Debug|Win32 23 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Debug|x64.ActiveCfg = Debug|x64 24 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Debug|x64.Build.0 = Debug|x64 25 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Release|Win32.ActiveCfg = Release|Win32 26 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Release|Win32.Build.0 = Release|Win32 27 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Release|x64.ActiveCfg = Release|x64 28 | {45CAFE1A-2ED4-44CA-9E3B-CA285A51F151}.Release|x64.Build.0 = Release|x64 29 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Debug|Win32.ActiveCfg = Debug|Win32 30 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Debug|Win32.Build.0 = Debug|Win32 31 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Debug|x64.ActiveCfg = Debug|x64 32 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Debug|x64.Build.0 = Debug|x64 33 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Release|Win32.ActiveCfg = Release|Win32 34 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Release|Win32.Build.0 = Release|Win32 35 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Release|x64.ActiveCfg = Release|x64 36 | {CFB36449-2482-411B-8082-86D0004DF9B7}.Release|x64.Build.0 = Release|x64 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /include/tbb/null_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_null_mutex_H 22 | #define __TBB_null_mutex_H 23 | 24 | #include "tbb_stddef.h" 25 | 26 | namespace tbb { 27 | 28 | //! A mutex which does nothing 29 | /** A null_mutex does no operation and simulates success. 30 | @ingroup synchronization */ 31 | class null_mutex : internal::mutex_copy_deprecated_and_disabled { 32 | public: 33 | //! Represents acquisition of a mutex. 34 | class scoped_lock : internal::no_copy { 35 | public: 36 | scoped_lock() {} 37 | scoped_lock( null_mutex& ) {} 38 | ~scoped_lock() {} 39 | void acquire( null_mutex& ) {} 40 | bool try_acquire( null_mutex& ) { return true; } 41 | void release() {} 42 | }; 43 | 44 | null_mutex() {} 45 | 46 | // Mutex traits 47 | static const bool is_rw_mutex = false; 48 | static const bool is_recursive_mutex = true; 49 | static const bool is_fair_mutex = true; 50 | }; 51 | 52 | } 53 | 54 | #endif /* __TBB_null_mutex_H */ 55 | -------------------------------------------------------------------------------- /include/tbb/null_rw_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_null_rw_mutex_H 22 | #define __TBB_null_rw_mutex_H 23 | 24 | #include "tbb_stddef.h" 25 | 26 | namespace tbb { 27 | 28 | //! A rw mutex which does nothing 29 | /** A null_rw_mutex is a rw mutex that does nothing and simulates successful operation. 30 | @ingroup synchronization */ 31 | class null_rw_mutex : internal::mutex_copy_deprecated_and_disabled { 32 | public: 33 | //! Represents acquisition of a mutex. 34 | class scoped_lock : internal::no_copy { 35 | public: 36 | scoped_lock() {} 37 | scoped_lock( null_rw_mutex& , bool = true ) {} 38 | ~scoped_lock() {} 39 | void acquire( null_rw_mutex& , bool = true ) {} 40 | bool upgrade_to_writer() { return true; } 41 | bool downgrade_to_reader() { return true; } 42 | bool try_acquire( null_rw_mutex& , bool = true ) { return true; } 43 | void release() {} 44 | }; 45 | 46 | null_rw_mutex() {} 47 | 48 | // Mutex traits 49 | static const bool is_rw_mutex = true; 50 | static const bool is_recursive_mutex = true; 51 | static const bool is_fair_mutex = true; 52 | }; 53 | 54 | } 55 | 56 | #endif /* __TBB_null_rw_mutex_H */ 57 | -------------------------------------------------------------------------------- /include/tbb/compat/ppl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_compat_ppl_H 22 | #define __TBB_compat_ppl_H 23 | 24 | #include "../task_group.h" 25 | #include "../parallel_invoke.h" 26 | #include "../parallel_for_each.h" 27 | #include "../parallel_for.h" 28 | #include "../tbb_exception.h" 29 | #include "../critical_section.h" 30 | #include "../reader_writer_lock.h" 31 | #include "../combinable.h" 32 | 33 | namespace Concurrency { 34 | 35 | #if __TBB_TASK_GROUP_CONTEXT 36 | using tbb::task_handle; 37 | using tbb::task_group_status; 38 | using tbb::task_group; 39 | using tbb::structured_task_group; 40 | using tbb::invalid_multiple_scheduling; 41 | using tbb::missing_wait; 42 | using tbb::make_task; 43 | 44 | using tbb::not_complete; 45 | using tbb::complete; 46 | using tbb::canceled; 47 | 48 | using tbb::is_current_task_group_canceling; 49 | #endif /* __TBB_TASK_GROUP_CONTEXT */ 50 | 51 | using tbb::parallel_invoke; 52 | using tbb::strict_ppl::parallel_for; 53 | using tbb::parallel_for_each; 54 | using tbb::critical_section; 55 | using tbb::reader_writer_lock; 56 | using tbb::combinable; 57 | 58 | using tbb::improper_lock; 59 | 60 | } // namespace Concurrency 61 | 62 | #endif /* __TBB_compat_ppl_H */ 63 | -------------------------------------------------------------------------------- /include/tbb/tbbmalloc_proxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | /* 22 | Replacing the standard memory allocation routines in Microsoft* C/C++ RTL 23 | (malloc/free, global new/delete, etc.) with the TBB memory allocator. 24 | 25 | Include the following header to a source of any binary which is loaded during 26 | application startup 27 | 28 | #include "tbb/tbbmalloc_proxy.h" 29 | 30 | or add following parameters to the linker options for the binary which is 31 | loaded during application startup. It can be either exe-file or dll. 32 | 33 | For win32 34 | tbbmalloc_proxy.lib /INCLUDE:"___TBB_malloc_proxy" 35 | win64 36 | tbbmalloc_proxy.lib /INCLUDE:"__TBB_malloc_proxy" 37 | */ 38 | 39 | #ifndef __TBB_tbbmalloc_proxy_H 40 | #define __TBB_tbbmalloc_proxy_H 41 | 42 | #if _MSC_VER 43 | 44 | #ifdef _DEBUG 45 | #pragma comment(lib, "tbbmalloc_proxy_debug.lib") 46 | #else 47 | #pragma comment(lib, "tbbmalloc_proxy.lib") 48 | #endif 49 | 50 | #if defined(_WIN64) 51 | #pragma comment(linker, "/include:__TBB_malloc_proxy") 52 | #else 53 | #pragma comment(linker, "/include:___TBB_malloc_proxy") 54 | #endif 55 | 56 | #else 57 | /* Primarily to support MinGW */ 58 | 59 | extern "C" void __TBB_malloc_proxy(); 60 | struct __TBB_malloc_proxy_caller { 61 | __TBB_malloc_proxy_caller() { __TBB_malloc_proxy(); } 62 | } volatile __TBB_malloc_proxy_helper_object; 63 | 64 | #endif // _MSC_VER 65 | 66 | #endif //__TBB_tbbmalloc_proxy_H 67 | -------------------------------------------------------------------------------- /include/tbb/machine/mic_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_mic_common_H 22 | #define __TBB_mic_common_H 23 | 24 | #ifndef __TBB_machine_H 25 | #error Do not #include this internal file directly; use public TBB headers instead. 26 | #endif 27 | 28 | #if ! __TBB_DEFINE_MIC 29 | #error mic_common.h should be included only when building for Intel(R) Many Integrated Core Architecture 30 | #endif 31 | 32 | #ifndef __TBB_PREFETCHING 33 | #define __TBB_PREFETCHING 1 34 | #endif 35 | #if __TBB_PREFETCHING 36 | #include 37 | #define __TBB_cl_prefetch(p) _mm_prefetch((const char*)p, _MM_HINT_T1) 38 | #define __TBB_cl_evict(p) _mm_clevict(p, _MM_HINT_T1) 39 | #endif 40 | 41 | /** Intel(R) Many Integrated Core Architecture does not support mfence and pause instructions **/ 42 | #define __TBB_full_memory_fence() __asm__ __volatile__("lock; addl $0,(%%rsp)":::"memory") 43 | #define __TBB_Pause(x) _mm_delay_32(16*(x)) 44 | #define __TBB_STEALING_PAUSE 1500/16 45 | #include 46 | #define __TBB_Yield() sched_yield() 47 | 48 | // low-level timing intrinsic and its type 49 | #define __TBB_machine_time_stamp() _rdtsc() 50 | typedef uint64_t machine_tsc_t; 51 | 52 | /** Specifics **/ 53 | #define __TBB_STEALING_ABORT_ON_CONTENTION 1 54 | #define __TBB_YIELD2P 1 55 | #define __TBB_HOARD_NONLOCAL_TASKS 1 56 | 57 | #if ! ( __FreeBSD__ || __linux__ ) 58 | #error Intel(R) Many Integrated Core Compiler does not define __FreeBSD__ or __linux__ anymore. Check for the __TBB_XXX_BROKEN defined under __FreeBSD__ or __linux__. 59 | #endif /* ! ( __FreeBSD__ || __linux__ ) */ 60 | 61 | #endif /* __TBB_mic_common_H */ 62 | -------------------------------------------------------------------------------- /include/tbb/combinable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_combinable_H 22 | #define __TBB_combinable_H 23 | 24 | #include "enumerable_thread_specific.h" 25 | #include "cache_aligned_allocator.h" 26 | 27 | namespace tbb { 28 | /** \name combinable 29 | **/ 30 | //@{ 31 | //! Thread-local storage with optional reduction 32 | /** @ingroup containers */ 33 | template 34 | class combinable { 35 | private: 36 | typedef typename tbb::cache_aligned_allocator my_alloc; 37 | 38 | typedef typename tbb::enumerable_thread_specific my_ets_type; 39 | my_ets_type my_ets; 40 | 41 | public: 42 | 43 | combinable() { } 44 | 45 | template 46 | combinable( finit _finit) : my_ets(_finit) { } 47 | 48 | //! destructor 49 | ~combinable() { 50 | } 51 | 52 | combinable(const combinable& other) : my_ets(other.my_ets) { } 53 | 54 | combinable & operator=( const combinable & other) { my_ets = other.my_ets; return *this; } 55 | 56 | void clear() { my_ets.clear(); } 57 | 58 | T& local() { return my_ets.local(); } 59 | 60 | T& local(bool & exists) { return my_ets.local(exists); } 61 | 62 | // combine_func_t has signature T(T,T) or T(const T&, const T&) 63 | template 64 | T combine(combine_func_t f_combine) { return my_ets.combine(f_combine); } 65 | 66 | // combine_func_t has signature void(T) or void(const T&) 67 | template 68 | void combine_each(combine_func_t f_combine) { my_ets.combine_each(f_combine); } 69 | 70 | }; 71 | } // namespace tbb 72 | #endif /* __TBB_combinable_H */ 73 | -------------------------------------------------------------------------------- /include/tbb/machine/linux_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_machine_H 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #include 26 | #define __TBB_Yield() sched_yield() 27 | 28 | #include 29 | /* Futex definitions */ 30 | #include 31 | 32 | #if defined(SYS_futex) 33 | 34 | #define __TBB_USE_FUTEX 1 35 | #include 36 | #include 37 | // Unfortunately, some versions of Linux do not have a header that defines FUTEX_WAIT and FUTEX_WAKE. 38 | 39 | #ifdef FUTEX_WAIT 40 | #define __TBB_FUTEX_WAIT FUTEX_WAIT 41 | #else 42 | #define __TBB_FUTEX_WAIT 0 43 | #endif 44 | 45 | #ifdef FUTEX_WAKE 46 | #define __TBB_FUTEX_WAKE FUTEX_WAKE 47 | #else 48 | #define __TBB_FUTEX_WAKE 1 49 | #endif 50 | 51 | #ifndef __TBB_ASSERT 52 | #error machine specific headers must be included after tbb_stddef.h 53 | #endif 54 | 55 | namespace tbb { 56 | 57 | namespace internal { 58 | 59 | inline int futex_wait( void *futex, int comparand ) { 60 | int r = syscall( SYS_futex,futex,__TBB_FUTEX_WAIT,comparand,NULL,NULL,0 ); 61 | #if TBB_USE_ASSERT 62 | int e = errno; 63 | __TBB_ASSERT( r==0||r==EWOULDBLOCK||(r==-1&&(e==EAGAIN||e==EINTR)), "futex_wait failed." ); 64 | #endif /* TBB_USE_ASSERT */ 65 | return r; 66 | } 67 | 68 | inline int futex_wakeup_one( void *futex ) { 69 | int r = ::syscall( SYS_futex,futex,__TBB_FUTEX_WAKE,1,NULL,NULL,0 ); 70 | __TBB_ASSERT( r==0||r==1, "futex_wakeup_one: more than one thread woken up?" ); 71 | return r; 72 | } 73 | 74 | inline int futex_wakeup_all( void *futex ) { 75 | int r = ::syscall( SYS_futex,futex,__TBB_FUTEX_WAKE,INT_MAX,NULL,NULL,0 ); 76 | __TBB_ASSERT( r>=0, "futex_wakeup_all: error in waking up threads" ); 77 | return r; 78 | } 79 | 80 | } /* namespace internal */ 81 | 82 | } /* namespace tbb */ 83 | 84 | #endif /* SYS_futex */ 85 | -------------------------------------------------------------------------------- /include/tbb/internal/_range_iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_range_iterator_H 22 | #define __TBB_range_iterator_H 23 | 24 | #include "../tbb_stddef.h" 25 | 26 | #if __TBB_CPP11_STD_BEGIN_END_PRESENT && __TBB_CPP11_AUTO_PRESENT && __TBB_CPP11_DECLTYPE_PRESENT 27 | #include 28 | #endif 29 | 30 | namespace tbb { 31 | // iterators to first and last elements of container 32 | namespace internal { 33 | 34 | #if __TBB_CPP11_STD_BEGIN_END_PRESENT && __TBB_CPP11_AUTO_PRESENT && __TBB_CPP11_DECLTYPE_PRESENT 35 | using std::begin; 36 | using std::end; 37 | template 38 | auto first(Container& c)-> decltype(begin(c)) {return begin(c);} 39 | 40 | template 41 | auto first(const Container& c)-> decltype(begin(c)) {return begin(c);} 42 | 43 | template 44 | auto last(Container& c)-> decltype(begin(c)) {return end(c);} 45 | 46 | template 47 | auto last(const Container& c)-> decltype(begin(c)) {return end(c);} 48 | #else 49 | template 50 | typename Container::iterator first(Container& c) {return c.begin();} 51 | 52 | template 53 | typename Container::const_iterator first(const Container& c) {return c.begin();} 54 | 55 | template 56 | typename Container::iterator last(Container& c) {return c.end();} 57 | 58 | template 59 | typename Container::const_iterator last(const Container& c) {return c.end();} 60 | #endif 61 | 62 | template 63 | T* first(T (&arr) [size]) {return arr;} 64 | 65 | template 66 | T* last(T (&arr) [size]) {return arr + size;} 67 | } //namespace internal 68 | } //namespace tbb 69 | 70 | #endif // __TBB_range_iterator_H 71 | -------------------------------------------------------------------------------- /include/tbb/internal/_tbb_windef.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_tbb_windef_H 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif /* __TBB_tbb_windef_H */ 24 | 25 | // Check that the target Windows version has all API calls requried for TBB. 26 | // Do not increase the version in condition beyond 0x0500 without prior discussion! 27 | #if defined(_WIN32_WINNT) && _WIN32_WINNT<0x0501 28 | #error TBB is unable to run on old Windows versions; _WIN32_WINNT must be 0x0501 or greater. 29 | #endif 30 | 31 | #if !defined(_MT) 32 | #error TBB requires linkage with multithreaded C/C++ runtime library. \ 33 | Choose multithreaded DLL runtime in project settings, or use /MD[d] compiler switch. 34 | #endif 35 | 36 | // Workaround for the problem with MVSC headers failing to define namespace std 37 | namespace std { 38 | using ::size_t; using ::ptrdiff_t; 39 | } 40 | 41 | #define __TBB_STRING_AUX(x) #x 42 | #define __TBB_STRING(x) __TBB_STRING_AUX(x) 43 | 44 | // Default setting of TBB_USE_DEBUG 45 | #ifdef TBB_USE_DEBUG 46 | # if TBB_USE_DEBUG 47 | # if !defined(_DEBUG) 48 | # pragma message(__FILE__ "(" __TBB_STRING(__LINE__) ") : Warning: Recommend using /MDd if compiling with TBB_USE_DEBUG!=0") 49 | # endif 50 | # else 51 | # if defined(_DEBUG) 52 | # pragma message(__FILE__ "(" __TBB_STRING(__LINE__) ") : Warning: Recommend using /MD if compiling with TBB_USE_DEBUG==0") 53 | # endif 54 | # endif 55 | #endif 56 | 57 | #if (__TBB_BUILD || __TBBMALLOC_BUILD) && !defined(__TBB_NO_IMPLICIT_LINKAGE) 58 | #define __TBB_NO_IMPLICIT_LINKAGE 1 59 | #endif 60 | 61 | #if _MSC_VER 62 | #if !__TBB_NO_IMPLICIT_LINKAGE 63 | #ifdef __TBB_LIB_NAME 64 | #pragma comment(lib, __TBB_STRING(__TBB_LIB_NAME)) 65 | #else 66 | #ifdef _DEBUG 67 | #pragma comment(lib, "tbb_debug.lib") 68 | #else 69 | #pragma comment(lib, "tbb.lib") 70 | #endif 71 | #endif 72 | #endif 73 | #endif 74 | -------------------------------------------------------------------------------- /include/tbb/tbb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_tbb_H 22 | #define __TBB_tbb_H 23 | 24 | /** 25 | This header bulk-includes declarations or definitions of all the functionality 26 | provided by TBB (save for malloc dependent headers). 27 | 28 | If you use only a few TBB constructs, consider including specific headers only. 29 | Any header listed below can be included independently of others. 30 | **/ 31 | 32 | #if TBB_PREVIEW_AGGREGATOR 33 | #include "aggregator.h" 34 | #endif 35 | #include "aligned_space.h" 36 | #include "atomic.h" 37 | #include "blocked_range.h" 38 | #include "blocked_range2d.h" 39 | #include "blocked_range3d.h" 40 | #include "cache_aligned_allocator.h" 41 | #include "combinable.h" 42 | #include "concurrent_hash_map.h" 43 | #if TBB_PREVIEW_CONCURRENT_LRU_CACHE 44 | #include "concurrent_lru_cache.h" 45 | #endif 46 | #include "concurrent_priority_queue.h" 47 | #include "concurrent_queue.h" 48 | #include "concurrent_unordered_map.h" 49 | #include "concurrent_unordered_set.h" 50 | #include "concurrent_vector.h" 51 | #include "critical_section.h" 52 | #include "enumerable_thread_specific.h" 53 | #include "flow_graph.h" 54 | #include "mutex.h" 55 | #include "null_mutex.h" 56 | #include "null_rw_mutex.h" 57 | #include "parallel_do.h" 58 | #include "parallel_for.h" 59 | #include "parallel_for_each.h" 60 | #include "parallel_invoke.h" 61 | #include "parallel_reduce.h" 62 | #include "parallel_scan.h" 63 | #include "parallel_sort.h" 64 | #include "partitioner.h" 65 | #include "pipeline.h" 66 | #include "queuing_mutex.h" 67 | #include "queuing_rw_mutex.h" 68 | #include "reader_writer_lock.h" 69 | #include "recursive_mutex.h" 70 | #include "spin_mutex.h" 71 | #include "spin_rw_mutex.h" 72 | #include "task.h" 73 | #include "task_arena.h" 74 | #include "task_group.h" 75 | #include "task_scheduler_init.h" 76 | #include "task_scheduler_observer.h" 77 | #include "tbb_allocator.h" 78 | #include "tbb_exception.h" 79 | #include "tbb_thread.h" 80 | #include "tick_count.h" 81 | 82 | #endif /* __TBB_tbb_H */ 83 | -------------------------------------------------------------------------------- /include/tbb/machine/windows_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_machine_windows_api_H 22 | #define __TBB_machine_windows_api_H 23 | 24 | #if _WIN32 || _WIN64 25 | 26 | #if _XBOX 27 | 28 | #define NONET 29 | #define NOD3D 30 | #include 31 | 32 | #else // Assume "usual" Windows 33 | 34 | #include 35 | 36 | #endif // _XBOX 37 | 38 | #if _WIN32_WINNT < 0x0600 39 | // The following Windows API function is declared explicitly; 40 | // otherwise it fails to compile by VS2005. 41 | #if !defined(WINBASEAPI) || (_WIN32_WINNT < 0x0501 && _MSC_VER == 1400) 42 | #define __TBB_WINBASEAPI extern "C" 43 | #else 44 | #define __TBB_WINBASEAPI WINBASEAPI 45 | #endif 46 | __TBB_WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION ); 47 | __TBB_WINBASEAPI BOOL WINAPI InitializeCriticalSectionAndSpinCount( LPCRITICAL_SECTION, DWORD ); 48 | // Overloading WINBASEAPI macro and using local functions missing in Windows XP/2003 49 | #define InitializeCriticalSectionEx inlineInitializeCriticalSectionEx 50 | #define CreateSemaphoreEx inlineCreateSemaphoreEx 51 | #define CreateEventEx inlineCreateEventEx 52 | inline BOOL WINAPI inlineInitializeCriticalSectionEx( LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD ) 53 | { 54 | return InitializeCriticalSectionAndSpinCount( lpCriticalSection, dwSpinCount ); 55 | } 56 | inline HANDLE WINAPI inlineCreateSemaphoreEx( LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName, DWORD, DWORD ) 57 | { 58 | return CreateSemaphore( lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName ); 59 | } 60 | inline HANDLE WINAPI inlineCreateEventEx( LPSECURITY_ATTRIBUTES lpEventAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD ) 61 | { 62 | BOOL manual_reset = dwFlags&0x00000001 ? TRUE : FALSE; // CREATE_EVENT_MANUAL_RESET 63 | BOOL initial_set = dwFlags&0x00000002 ? TRUE : FALSE; // CREATE_EVENT_INITIAL_SET 64 | return CreateEvent( lpEventAttributes, manual_reset, initial_set, lpName ); 65 | } 66 | #endif 67 | 68 | #if defined(RTL_SRWLOCK_INIT) 69 | #ifndef __TBB_USE_SRWLOCK 70 | // TODO: turn it on when bug 1952 will be fixed 71 | #define __TBB_USE_SRWLOCK 0 72 | #endif 73 | #endif 74 | 75 | #else 76 | #error tbb/machine/windows_api.h should only be used for Windows based platforms 77 | #endif // _WIN32 || _WIN64 78 | 79 | #endif // __TBB_machine_windows_api_H 80 | -------------------------------------------------------------------------------- /include/tbb/machine/ibm_aix51.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | // TODO: revise by comparing with mac_ppc.h 22 | 23 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_ibm_aix51_H) 24 | #error Do not #include this internal file directly; use public TBB headers instead. 25 | #endif 26 | 27 | #define __TBB_machine_ibm_aix51_H 28 | 29 | #define __TBB_WORDSIZE 8 30 | #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG // assumption based on operating system 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | extern "C" { 37 | int32_t __TBB_machine_cas_32 (volatile void* ptr, int32_t value, int32_t comparand); 38 | int64_t __TBB_machine_cas_64 (volatile void* ptr, int64_t value, int64_t comparand); 39 | void __TBB_machine_flush (); 40 | void __TBB_machine_lwsync (); 41 | void __TBB_machine_isync (); 42 | } 43 | 44 | // Mapping of old entry point names retained for the sake of backward binary compatibility 45 | #define __TBB_machine_cmpswp4 __TBB_machine_cas_32 46 | #define __TBB_machine_cmpswp8 __TBB_machine_cas_64 47 | 48 | #define __TBB_Yield() sched_yield() 49 | 50 | #define __TBB_USE_GENERIC_PART_WORD_CAS 1 51 | #define __TBB_USE_GENERIC_FETCH_ADD 1 52 | #define __TBB_USE_GENERIC_FETCH_STORE 1 53 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 54 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 55 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 56 | 57 | #if __GNUC__ 58 | #define __TBB_control_consistency_helper() __asm__ __volatile__( "isync": : :"memory") 59 | #define __TBB_acquire_consistency_helper() __asm__ __volatile__("lwsync": : :"memory") 60 | #define __TBB_release_consistency_helper() __asm__ __volatile__("lwsync": : :"memory") 61 | #define __TBB_full_memory_fence() __asm__ __volatile__( "sync": : :"memory") 62 | #else 63 | // IBM C++ Compiler does not support inline assembly 64 | // TODO: Since XL 9.0 or earlier GCC syntax is supported. Replace with more 65 | // lightweight implementation (like in mac_ppc.h) 66 | #define __TBB_control_consistency_helper() __TBB_machine_isync () 67 | #define __TBB_acquire_consistency_helper() __TBB_machine_lwsync () 68 | #define __TBB_release_consistency_helper() __TBB_machine_lwsync () 69 | #define __TBB_full_memory_fence() __TBB_machine_flush () 70 | #endif 71 | -------------------------------------------------------------------------------- /include/tbb/internal/_tbb_strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | TBB_STRING_RESOURCE(FLOW_BROADCAST_NODE, "broadcast_node") 22 | TBB_STRING_RESOURCE(FLOW_BUFFER_NODE, "buffer_node") 23 | TBB_STRING_RESOURCE(FLOW_CONTINUE_NODE, "continue_node") 24 | TBB_STRING_RESOURCE(FLOW_FUNCTION_NODE, "function_node") 25 | TBB_STRING_RESOURCE(FLOW_JOIN_NODE_QUEUEING, "join_node (queueing)") 26 | TBB_STRING_RESOURCE(FLOW_JOIN_NODE_RESERVING, "join_node (reserving)") 27 | TBB_STRING_RESOURCE(FLOW_JOIN_NODE_TAG_MATCHING, "join_node (tag_matching)") 28 | TBB_STRING_RESOURCE(FLOW_LIMITER_NODE, "limiter_node") 29 | TBB_STRING_RESOURCE(FLOW_MULTIFUNCTION_NODE, "multifunction_node") 30 | TBB_STRING_RESOURCE(FLOW_OR_NODE, "or_node") //no longer in use, kept for backward compatibilty 31 | TBB_STRING_RESOURCE(FLOW_OVERWRITE_NODE, "overwrite_node") 32 | TBB_STRING_RESOURCE(FLOW_PRIORITY_QUEUE_NODE, "priority_queue_node") 33 | TBB_STRING_RESOURCE(FLOW_QUEUE_NODE, "queue_node") 34 | TBB_STRING_RESOURCE(FLOW_SEQUENCER_NODE, "sequencer_node") 35 | TBB_STRING_RESOURCE(FLOW_SOURCE_NODE, "source_node") 36 | TBB_STRING_RESOURCE(FLOW_SPLIT_NODE, "split_node") 37 | TBB_STRING_RESOURCE(FLOW_WRITE_ONCE_NODE, "write_once_node") 38 | TBB_STRING_RESOURCE(FLOW_BODY, "body") 39 | TBB_STRING_RESOURCE(FLOW_GRAPH, "graph") 40 | TBB_STRING_RESOURCE(FLOW_NODE, "node") 41 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT, "input_port") 42 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_0, "input_port_0") 43 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_1, "input_port_1") 44 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_2, "input_port_2") 45 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_3, "input_port_3") 46 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_4, "input_port_4") 47 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_5, "input_port_5") 48 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_6, "input_port_6") 49 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_7, "input_port_7") 50 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_8, "input_port_8") 51 | TBB_STRING_RESOURCE(FLOW_INPUT_PORT_9, "input_port_9") 52 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT, "output_port") 53 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_0, "output_port_0") 54 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_1, "output_port_1") 55 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_2, "output_port_2") 56 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_3, "output_port_3") 57 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_4, "output_port_4") 58 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_5, "output_port_5") 59 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_6, "output_port_6") 60 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_7, "output_port_7") 61 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_8, "output_port_8") 62 | TBB_STRING_RESOURCE(FLOW_OUTPUT_PORT_9, "output_port_9") 63 | TBB_STRING_RESOURCE(FLOW_OBJECT_NAME, "object_name") 64 | TBB_STRING_RESOURCE(FLOW_NULL, "null") 65 | TBB_STRING_RESOURCE(FLOW_INDEXER_NODE, "indexer_node") 66 | -------------------------------------------------------------------------------- /include/tbb/parallel_for_each.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_parallel_for_each_H 22 | #define __TBB_parallel_for_each_H 23 | 24 | #include "parallel_do.h" 25 | 26 | namespace tbb { 27 | 28 | //! @cond INTERNAL 29 | namespace internal { 30 | // The class calls user function in operator() 31 | template 32 | class parallel_for_each_body : internal::no_assign { 33 | const Function &my_func; 34 | public: 35 | parallel_for_each_body(const Function &_func) : my_func(_func) {} 36 | parallel_for_each_body(const parallel_for_each_body &_caller) : my_func(_caller.my_func) {} 37 | 38 | void operator() ( typename std::iterator_traits::reference value ) const { 39 | my_func(value); 40 | } 41 | }; 42 | } // namespace internal 43 | //! @endcond 44 | 45 | /** \name parallel_for_each 46 | **/ 47 | //@{ 48 | //! Calls function f for all items from [first, last) interval using user-supplied context 49 | /** @ingroup algorithms */ 50 | #if __TBB_TASK_GROUP_CONTEXT 51 | template 52 | void parallel_for_each(InputIterator first, InputIterator last, const Function& f, task_group_context &context) { 53 | internal::parallel_for_each_body body(f); 54 | tbb::parallel_do (first, last, body, context); 55 | } 56 | 57 | //! Calls function f for all items from rng using user-supplied context 58 | /** @ingroup algorithms */ 59 | template 60 | void parallel_for_each(Range& rng, const Function& f, task_group_context& context) { 61 | parallel_for_each(tbb::internal::first(rng), tbb::internal::last(rng), f, context); 62 | } 63 | 64 | //! Calls function f for all items from const rng user-supplied context 65 | /** @ingroup algorithms */ 66 | template 67 | void parallel_for_each(const Range& rng, const Function& f, task_group_context& context) { 68 | parallel_for_each(tbb::internal::first(rng), tbb::internal::last(rng), f, context); 69 | } 70 | #endif /* __TBB_TASK_GROUP_CONTEXT */ 71 | 72 | //! Uses default context 73 | template 74 | void parallel_for_each(InputIterator first, InputIterator last, const Function& f) { 75 | internal::parallel_for_each_body body(f); 76 | tbb::parallel_do (first, last, body); 77 | } 78 | 79 | //! Uses default context 80 | template 81 | void parallel_for_each(Range& rng, const Function& f) { 82 | parallel_for_each(tbb::internal::first(rng), tbb::internal::last(rng), f); 83 | } 84 | 85 | //! Uses default context 86 | template 87 | void parallel_for_each(const Range& rng, const Function& f) { 88 | parallel_for_each(tbb::internal::first(rng), tbb::internal::last(rng), f); 89 | } 90 | 91 | //@} 92 | 93 | } // namespace 94 | 95 | #endif /* __TBB_parallel_for_each_H */ 96 | -------------------------------------------------------------------------------- /include/tbb/blocked_range2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_blocked_range2d_H 22 | #define __TBB_blocked_range2d_H 23 | 24 | #include "tbb_stddef.h" 25 | #include "blocked_range.h" 26 | 27 | namespace tbb { 28 | 29 | //! A 2-dimensional range that models the Range concept. 30 | /** @ingroup algorithms */ 31 | template 32 | class blocked_range2d { 33 | public: 34 | //! Type for size of an iteration range 35 | typedef blocked_range row_range_type; 36 | typedef blocked_range col_range_type; 37 | 38 | private: 39 | row_range_type my_rows; 40 | col_range_type my_cols; 41 | 42 | public: 43 | 44 | blocked_range2d( RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize, 45 | ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) : 46 | my_rows(row_begin,row_end,row_grainsize), 47 | my_cols(col_begin,col_end,col_grainsize) 48 | { 49 | } 50 | 51 | blocked_range2d( RowValue row_begin, RowValue row_end, 52 | ColValue col_begin, ColValue col_end ) : 53 | my_rows(row_begin,row_end), 54 | my_cols(col_begin,col_end) 55 | { 56 | } 57 | 58 | //! True if range is empty 59 | bool empty() const { 60 | // Yes, it is a logical OR here, not AND. 61 | return my_rows.empty() || my_cols.empty(); 62 | } 63 | 64 | //! True if range is divisible into two pieces. 65 | bool is_divisible() const { 66 | return my_rows.is_divisible() || my_cols.is_divisible(); 67 | } 68 | 69 | blocked_range2d( blocked_range2d& r, split ) : 70 | my_rows(r.my_rows), 71 | my_cols(r.my_cols) 72 | { 73 | split split_obj; 74 | do_split(r, split_obj); 75 | } 76 | 77 | #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES 78 | //! Static field to support proportional split 79 | static const bool is_divisible_in_proportion = true; 80 | 81 | blocked_range2d( blocked_range2d& r, proportional_split& proportion ) : 82 | my_rows(r.my_rows), 83 | my_cols(r.my_cols) 84 | { 85 | do_split(r, proportion); 86 | } 87 | #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */ 88 | 89 | template 90 | void do_split( blocked_range2d& r, Split& split_obj ) 91 | { 92 | if( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) { 93 | my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj); 94 | } else { 95 | my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj); 96 | } 97 | } 98 | 99 | //! The rows of the iteration space 100 | const row_range_type& rows() const {return my_rows;} 101 | 102 | //! The columns of the iteration space 103 | const col_range_type& cols() const {return my_cols;} 104 | }; 105 | 106 | } // namespace tbb 107 | 108 | #endif /* __TBB_blocked_range2d_H */ 109 | -------------------------------------------------------------------------------- /include/tbb/machine/gcc_ia32_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_machine_gcc_ia32_common_H 22 | #define __TBB_machine_gcc_ia32_common_H 23 | 24 | //TODO: Add a higher-level function, e.g. tbb::interal::log2(), into tbb_stddef.h, which 25 | //uses __TBB_Log2 and contains the assert and remove the assert from here and all other 26 | //platform-specific headers. 27 | //TODO: Check if use of gcc intrinsic gives a better chance for cross call optimizations 28 | template 29 | static inline intptr_t __TBB_machine_lg( T x ) { 30 | __TBB_ASSERT(x>0, "The logarithm of a non-positive value is undefined."); 31 | uintptr_t j; 32 | __asm__("bsr %1,%0" : "=r"(j) : "r"((uintptr_t)x)); 33 | return j; 34 | } 35 | #define __TBB_Log2(V) __TBB_machine_lg(V) 36 | 37 | #ifndef __TBB_Pause 38 | //TODO: check if raising a ratio of pause instructions to loop control instructions 39 | //(via e.g. loop unrolling) gives any benefit for HT. E.g, the current implementation 40 | //does about 2 CPU-consuming instructions for every pause instruction. Perhaps for 41 | //high pause counts it should use an unrolled loop to raise the ratio, and thus free 42 | //up more integer cycles for the other hyperthread. On the other hand, if the loop is 43 | //unrolled too far, it won't fit in the core's loop cache, and thus take away 44 | //instruction decode slots from the other hyperthread. 45 | 46 | //TODO: check if use of gcc __builtin_ia32_pause intrinsic gives a "some how" better performing code 47 | static inline void __TBB_machine_pause( int32_t delay ) { 48 | for (int32_t i = 0; i < delay; i++) { 49 | __asm__ __volatile__("pause;"); 50 | } 51 | return; 52 | } 53 | #define __TBB_Pause(V) __TBB_machine_pause(V) 54 | #endif /* !__TBB_Pause */ 55 | 56 | // API to retrieve/update FPU control setting 57 | #ifndef __TBB_CPU_CTL_ENV_PRESENT 58 | #define __TBB_CPU_CTL_ENV_PRESENT 1 59 | namespace tbb { 60 | namespace internal { 61 | class cpu_ctl_env { 62 | private: 63 | int mxcsr; 64 | short x87cw; 65 | static const int MXCSR_CONTROL_MASK = ~0x3f; /* all except last six status bits */ 66 | public: 67 | bool operator!=( const cpu_ctl_env& ctl ) const { return mxcsr != ctl.mxcsr || x87cw != ctl.x87cw; } 68 | void get_env() { 69 | #if __TBB_ICC_12_0_INL_ASM_FSTCW_BROKEN 70 | cpu_ctl_env loc_ctl; 71 | __asm__ __volatile__ ( 72 | "stmxcsr %0\n\t" 73 | "fstcw %1" 74 | : "=m"(loc_ctl.mxcsr), "=m"(loc_ctl.x87cw) 75 | ); 76 | *this = loc_ctl; 77 | #else 78 | __asm__ __volatile__ ( 79 | "stmxcsr %0\n\t" 80 | "fstcw %1" 81 | : "=m"(mxcsr), "=m"(x87cw) 82 | ); 83 | #endif 84 | mxcsr &= MXCSR_CONTROL_MASK; 85 | } 86 | void set_env() const { 87 | __asm__ __volatile__ ( 88 | "ldmxcsr %0\n\t" 89 | "fldcw %1" 90 | : : "m"(mxcsr), "m"(x87cw) 91 | ); 92 | } 93 | }; 94 | } // namespace internal 95 | } // namespace tbb 96 | #endif /* !__TBB_CPU_CTL_ENV_PRESENT */ 97 | 98 | #include "gcc_itsx.h" 99 | 100 | #endif /* __TBB_machine_gcc_ia32_common_H */ 101 | -------------------------------------------------------------------------------- /include/tbb/queuing_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_queuing_mutex_H 22 | #define __TBB_queuing_mutex_H 23 | 24 | #include "tbb_config.h" 25 | 26 | #if !TBB_USE_EXCEPTIONS && _MSC_VER 27 | // Suppress "C++ exception handler used, but unwind semantics are not enabled" warning in STL headers 28 | #pragma warning (push) 29 | #pragma warning (disable: 4530) 30 | #endif 31 | 32 | #include 33 | 34 | #if !TBB_USE_EXCEPTIONS && _MSC_VER 35 | #pragma warning (pop) 36 | #endif 37 | 38 | #include "atomic.h" 39 | #include "tbb_profiling.h" 40 | 41 | namespace tbb { 42 | 43 | //! Queuing mutex with local-only spinning. 44 | /** @ingroup synchronization */ 45 | class queuing_mutex : internal::mutex_copy_deprecated_and_disabled { 46 | public: 47 | //! Construct unacquired mutex. 48 | queuing_mutex() { 49 | q_tail = NULL; 50 | #if TBB_USE_THREADING_TOOLS 51 | internal_construct(); 52 | #endif 53 | } 54 | 55 | //! The scoped locking pattern 56 | /** It helps to avoid the common problem of forgetting to release lock. 57 | It also nicely provides the "node" for queuing locks. */ 58 | class scoped_lock: internal::no_copy { 59 | //! Initialize fields to mean "no lock held". 60 | void initialize() { 61 | mutex = NULL; 62 | #if TBB_USE_ASSERT 63 | internal::poison_pointer(next); 64 | #endif /* TBB_USE_ASSERT */ 65 | } 66 | 67 | public: 68 | //! Construct lock that has not acquired a mutex. 69 | /** Equivalent to zero-initialization of *this. */ 70 | scoped_lock() {initialize();} 71 | 72 | //! Acquire lock on given mutex. 73 | scoped_lock( queuing_mutex& m ) { 74 | initialize(); 75 | acquire(m); 76 | } 77 | 78 | //! Release lock (if lock is held). 79 | ~scoped_lock() { 80 | if( mutex ) release(); 81 | } 82 | 83 | //! Acquire lock on given mutex. 84 | void __TBB_EXPORTED_METHOD acquire( queuing_mutex& m ); 85 | 86 | //! Acquire lock on given mutex if free (i.e. non-blocking) 87 | bool __TBB_EXPORTED_METHOD try_acquire( queuing_mutex& m ); 88 | 89 | //! Release lock. 90 | void __TBB_EXPORTED_METHOD release(); 91 | 92 | private: 93 | //! The pointer to the mutex owned, or NULL if not holding a mutex. 94 | queuing_mutex* mutex; 95 | 96 | //! The pointer to the next competitor for a mutex 97 | scoped_lock *next; 98 | 99 | //! The local spin-wait variable 100 | /** Inverted (0 - blocked, 1 - acquired the mutex) for the sake of 101 | zero-initialization. Defining it as an entire word instead of 102 | a byte seems to help performance slightly. */ 103 | uintptr_t going; 104 | }; 105 | 106 | void __TBB_EXPORTED_METHOD internal_construct(); 107 | 108 | // Mutex traits 109 | static const bool is_rw_mutex = false; 110 | static const bool is_recursive_mutex = false; 111 | static const bool is_fair_mutex = true; 112 | 113 | private: 114 | //! The last competitor requesting the lock 115 | atomic q_tail; 116 | 117 | }; 118 | 119 | __TBB_DEFINE_PROFILING_SET_NAME(queuing_mutex) 120 | 121 | } // namespace tbb 122 | 123 | #endif /* __TBB_queuing_mutex_H */ 124 | -------------------------------------------------------------------------------- /include/tbb/internal/_mutex_padding.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_mutex_padding_H 22 | #define __TBB_mutex_padding_H 23 | 24 | // wrapper for padding mutexes to be alone on a cache line, without requiring they be allocated 25 | // from a pool. Because we allow them to be defined anywhere they must be two cache lines in size. 26 | 27 | 28 | namespace tbb { 29 | namespace interface7 { 30 | namespace internal { 31 | 32 | static const size_t cache_line_size = 64; 33 | 34 | // Pad a mutex to occupy a number of full cache lines sufficient to avoid false sharing 35 | // with other data; space overhead is up to 2*cache_line_size-1. 36 | template class padded_mutex; 37 | 38 | template 39 | class padded_mutex : tbb::internal::mutex_copy_deprecated_and_disabled { 40 | typedef long pad_type; 41 | pad_type my_pad[((sizeof(Mutex)+cache_line_size-1)/cache_line_size+1)*cache_line_size/sizeof(pad_type)]; 42 | 43 | Mutex *impl() { return (Mutex *)((uintptr_t(this)|(cache_line_size-1))+1);} 44 | 45 | public: 46 | static const bool is_rw_mutex = Mutex::is_rw_mutex; 47 | static const bool is_recursive_mutex = Mutex::is_recursive_mutex; 48 | static const bool is_fair_mutex = Mutex::is_fair_mutex; 49 | 50 | padded_mutex() { new(impl()) Mutex(); } 51 | ~padded_mutex() { impl()->~Mutex(); } 52 | 53 | //! Represents acquisition of a mutex. 54 | class scoped_lock : tbb::internal::no_copy { 55 | typename Mutex::scoped_lock my_scoped_lock; 56 | public: 57 | scoped_lock() : my_scoped_lock() {} 58 | scoped_lock( padded_mutex& m ) : my_scoped_lock(*m.impl()) { } 59 | ~scoped_lock() { } 60 | 61 | void acquire( padded_mutex& m ) { my_scoped_lock.acquire(*m.impl()); } 62 | bool try_acquire( padded_mutex& m ) { return my_scoped_lock.try_acquire(*m.impl()); } 63 | void release() { my_scoped_lock.release(); } 64 | }; 65 | }; 66 | 67 | template 68 | class padded_mutex : tbb::internal::mutex_copy_deprecated_and_disabled { 69 | typedef long pad_type; 70 | pad_type my_pad[((sizeof(Mutex)+cache_line_size-1)/cache_line_size+1)*cache_line_size/sizeof(pad_type)]; 71 | 72 | Mutex *impl() { return (Mutex *)((uintptr_t(this)|(cache_line_size-1))+1);} 73 | 74 | public: 75 | static const bool is_rw_mutex = Mutex::is_rw_mutex; 76 | static const bool is_recursive_mutex = Mutex::is_recursive_mutex; 77 | static const bool is_fair_mutex = Mutex::is_fair_mutex; 78 | 79 | padded_mutex() { new(impl()) Mutex(); } 80 | ~padded_mutex() { impl()->~Mutex(); } 81 | 82 | //! Represents acquisition of a mutex. 83 | class scoped_lock : tbb::internal::no_copy { 84 | typename Mutex::scoped_lock my_scoped_lock; 85 | public: 86 | scoped_lock() : my_scoped_lock() {} 87 | scoped_lock( padded_mutex& m, bool write = true ) : my_scoped_lock(*m.impl(),write) { } 88 | ~scoped_lock() { } 89 | 90 | void acquire( padded_mutex& m, bool write = true ) { my_scoped_lock.acquire(*m.impl(),write); } 91 | bool try_acquire( padded_mutex& m, bool write = true ) { return my_scoped_lock.try_acquire(*m.impl(),write); } 92 | bool upgrade_to_writer() { return my_scoped_lock.upgrade_to_writer(); } 93 | bool downgrade_to_reader() { return my_scoped_lock.downgrade_to_reader(); } 94 | void release() { my_scoped_lock.release(); } 95 | }; 96 | }; 97 | 98 | } // namespace internal 99 | } // namespace interface7 100 | } // namespace tbb 101 | 102 | #endif /* __TBB_mutex_padding_H */ 103 | -------------------------------------------------------------------------------- /include/tbb/critical_section.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef _TBB_CRITICAL_SECTION_H_ 22 | #define _TBB_CRITICAL_SECTION_H_ 23 | 24 | #if _WIN32||_WIN64 25 | #include "machine/windows_api.h" 26 | #else 27 | #include 28 | #include 29 | #endif // _WIN32||WIN64 30 | 31 | #include "tbb_stddef.h" 32 | #include "tbb_thread.h" 33 | #include "tbb_exception.h" 34 | 35 | #include "tbb_profiling.h" 36 | 37 | namespace tbb { 38 | 39 | namespace internal { 40 | class critical_section_v4 : internal::no_copy { 41 | #if _WIN32||_WIN64 42 | CRITICAL_SECTION my_impl; 43 | #else 44 | pthread_mutex_t my_impl; 45 | #endif 46 | tbb_thread::id my_tid; 47 | public: 48 | 49 | void __TBB_EXPORTED_METHOD internal_construct(); 50 | 51 | critical_section_v4() { 52 | #if _WIN32||_WIN64 53 | InitializeCriticalSectionEx( &my_impl, 4000, 0 ); 54 | #else 55 | pthread_mutex_init(&my_impl, NULL); 56 | #endif 57 | internal_construct(); 58 | } 59 | 60 | ~critical_section_v4() { 61 | __TBB_ASSERT(my_tid == tbb_thread::id(), "Destroying a still-held critical section"); 62 | #if _WIN32||_WIN64 63 | DeleteCriticalSection(&my_impl); 64 | #else 65 | pthread_mutex_destroy(&my_impl); 66 | #endif 67 | } 68 | 69 | class scoped_lock : internal::no_copy { 70 | private: 71 | critical_section_v4 &my_crit; 72 | public: 73 | scoped_lock( critical_section_v4& lock_me) :my_crit(lock_me) { 74 | my_crit.lock(); 75 | } 76 | 77 | ~scoped_lock() { 78 | my_crit.unlock(); 79 | } 80 | }; 81 | 82 | void lock() { 83 | tbb_thread::id local_tid = this_tbb_thread::get_id(); 84 | if(local_tid == my_tid) throw_exception( eid_improper_lock ); 85 | #if _WIN32||_WIN64 86 | EnterCriticalSection( &my_impl ); 87 | #else 88 | int rval = pthread_mutex_lock(&my_impl); 89 | __TBB_ASSERT_EX(!rval, "critical_section::lock: pthread_mutex_lock failed"); 90 | #endif 91 | __TBB_ASSERT(my_tid == tbb_thread::id(), NULL); 92 | my_tid = local_tid; 93 | } 94 | 95 | bool try_lock() { 96 | bool gotlock; 97 | tbb_thread::id local_tid = this_tbb_thread::get_id(); 98 | if(local_tid == my_tid) return false; 99 | #if _WIN32||_WIN64 100 | gotlock = TryEnterCriticalSection( &my_impl ) != 0; 101 | #else 102 | int rval = pthread_mutex_trylock(&my_impl); 103 | // valid returns are 0 (locked) and [EBUSY] 104 | __TBB_ASSERT(rval == 0 || rval == EBUSY, "critical_section::trylock: pthread_mutex_trylock failed"); 105 | gotlock = rval == 0; 106 | #endif 107 | if(gotlock) { 108 | my_tid = local_tid; 109 | } 110 | return gotlock; 111 | } 112 | 113 | void unlock() { 114 | __TBB_ASSERT(this_tbb_thread::get_id() == my_tid, "thread unlocking critical_section is not thread that locked it"); 115 | my_tid = tbb_thread::id(); 116 | #if _WIN32||_WIN64 117 | LeaveCriticalSection( &my_impl ); 118 | #else 119 | int rval = pthread_mutex_unlock(&my_impl); 120 | __TBB_ASSERT_EX(!rval, "critical_section::unlock: pthread_mutex_unlock failed"); 121 | #endif 122 | } 123 | 124 | static const bool is_rw_mutex = false; 125 | static const bool is_recursive_mutex = false; 126 | static const bool is_fair_mutex = true; 127 | }; // critical_section_v4 128 | } // namespace internal 129 | typedef internal::critical_section_v4 critical_section; 130 | 131 | __TBB_DEFINE_PROFILING_SET_NAME(critical_section) 132 | } // namespace tbb 133 | #endif // _TBB_CRITICAL_SECTION_H_ 134 | -------------------------------------------------------------------------------- /include/tbb/machine/xbox360_ppc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | // TODO: revise by comparing with mac_ppc.h 22 | 23 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_xbox360_ppc_H) 24 | #error Do not #include this internal file directly; use public TBB headers instead. 25 | #endif 26 | 27 | #define __TBB_machine_xbox360_ppc_H 28 | 29 | #define NONET 30 | #define NOD3D 31 | #include "xtl.h" 32 | #include "ppcintrinsics.h" 33 | 34 | #if _MSC_VER >= 1300 35 | extern "C" void _MemoryBarrier(); 36 | #pragma intrinsic(_MemoryBarrier) 37 | #define __TBB_control_consistency_helper() __isync() 38 | #define __TBB_acquire_consistency_helper() _MemoryBarrier() 39 | #define __TBB_release_consistency_helper() _MemoryBarrier() 40 | #endif 41 | 42 | #define __TBB_full_memory_fence() __sync() 43 | 44 | #define __TBB_WORDSIZE 4 45 | #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG 46 | 47 | //todo: define __TBB_USE_FENCED_ATOMICS and define acquire/release primitives to maximize performance 48 | 49 | inline __int32 __TBB_machine_cmpswp4(volatile void *ptr, __int32 value, __int32 comparand ) { 50 | __sync(); 51 | __int32 result = InterlockedCompareExchange((volatile LONG*)ptr, value, comparand); 52 | __isync(); 53 | return result; 54 | } 55 | 56 | inline __int64 __TBB_machine_cmpswp8(volatile void *ptr, __int64 value, __int64 comparand ) 57 | { 58 | __sync(); 59 | __int64 result = InterlockedCompareExchange64((volatile LONG64*)ptr, value, comparand); 60 | __isync(); 61 | return result; 62 | } 63 | 64 | #define __TBB_USE_GENERIC_PART_WORD_CAS 1 65 | #define __TBB_USE_GENERIC_FETCH_ADD 1 66 | #define __TBB_USE_GENERIC_FETCH_STORE 1 67 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 68 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 69 | #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1 70 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 71 | 72 | #pragma optimize( "", off ) 73 | inline void __TBB_machine_pause (__int32 delay ) 74 | { 75 | for (__int32 i=0; i> 0) & 1) + 93 | ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 1) & 1) + 94 | ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 2) & 1) + 95 | ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 3) & 1) + 96 | ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 4) & 1) + 97 | ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 5) & 1) + 1; // +1 accomodates for the master thread 98 | } 99 | 100 | static inline int __TBB_XBOX360_GetHardwareThreadIndex(int workerThreadIndex) 101 | { 102 | workerThreadIndex %= __TBB_XBOX360_DetectNumberOfWorkers()-1; 103 | int m = __TBB_XBOX360_HARDWARE_THREAD_MASK; 104 | int index = 0; 105 | int skipcount = workerThreadIndex; 106 | while (true) 107 | { 108 | if ((m & 1)!=0) 109 | { 110 | if (skipcount==0) break; 111 | skipcount--; 112 | } 113 | m >>= 1; 114 | index++; 115 | } 116 | return index; 117 | } 118 | 119 | #define __TBB_HardwareConcurrency() __TBB_XBOX360_DetectNumberOfWorkers() 120 | -------------------------------------------------------------------------------- /include/tbb/machine/gcc_itsx.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_gcc_itsx_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_gcc_itsx_H 26 | 27 | #define __TBB_OP_XACQUIRE 0xF2 28 | #define __TBB_OP_XRELEASE 0xF3 29 | #define __TBB_OP_LOCK 0xF0 30 | 31 | #define __TBB_STRINGIZE_INTERNAL(arg) #arg 32 | #define __TBB_STRINGIZE(arg) __TBB_STRINGIZE_INTERNAL(arg) 33 | 34 | #ifdef __TBB_x86_64 35 | #define __TBB_r_out "=r" 36 | #else 37 | #define __TBB_r_out "=q" 38 | #endif 39 | 40 | inline static uint8_t __TBB_machine_try_lock_elided( volatile uint8_t* lk ) 41 | { 42 | uint8_t value = 1; 43 | __asm__ volatile (".byte " __TBB_STRINGIZE(__TBB_OP_XACQUIRE)"; lock; xchgb %0, %1;" 44 | : __TBB_r_out(value), "=m"(*lk) : "0"(value), "m"(*lk) : "memory" ); 45 | return uint8_t(value^1); 46 | } 47 | 48 | inline static void __TBB_machine_try_lock_elided_cancel() 49 | { 50 | // 'pause' instruction aborts HLE/RTM transactions 51 | __asm__ volatile ("pause\n" : : : "memory" ); 52 | } 53 | 54 | inline static void __TBB_machine_unlock_elided( volatile uint8_t* lk ) 55 | { 56 | __asm__ volatile (".byte " __TBB_STRINGIZE(__TBB_OP_XRELEASE)"; movb $0, %0" 57 | : "=m"(*lk) : "m"(*lk) : "memory" ); 58 | } 59 | 60 | #if __TBB_TSX_INTRINSICS_PRESENT 61 | #include 62 | 63 | #define __TBB_machine_is_in_transaction _xtest 64 | #define __TBB_machine_begin_transaction _xbegin 65 | #define __TBB_machine_end_transaction _xend 66 | #define __TBB_machine_transaction_conflict_abort() _xabort(0xff) 67 | 68 | #else 69 | 70 | /*! 71 | * Check if the instruction is executed in a transaction or not 72 | */ 73 | inline static bool __TBB_machine_is_in_transaction() 74 | { 75 | int8_t res = 0; 76 | #if __TBB_x86_32 77 | __asm__ volatile (".byte 0x0F; .byte 0x01; .byte 0xD6;\n" 78 | "setz %0" : "=q"(res) : : "memory" ); 79 | #else 80 | __asm__ volatile (".byte 0x0F; .byte 0x01; .byte 0xD6;\n" 81 | "setz %0" : "=r"(res) : : "memory" ); 82 | #endif 83 | return res==0; 84 | } 85 | 86 | /*! 87 | * Enter speculative execution mode. 88 | * @return -1 on success 89 | * abort cause ( or 0 ) on abort 90 | */ 91 | inline static uint32_t __TBB_machine_begin_transaction() 92 | { 93 | uint32_t res = ~uint32_t(0); // success value 94 | __asm__ volatile ("1: .byte 0xC7; .byte 0xF8;\n" // XBEGIN 95 | " .long 2f-1b-6\n" // 2f-1b == difference in addresses of start 96 | // of XBEGIN and the MOVL 97 | // 2f - 1b - 6 == that difference minus the size of the 98 | // XBEGIN instruction. This is the abort offset to 99 | // 2: below. 100 | " jmp 3f\n" // success (leave -1 in res) 101 | "2: movl %%eax,%0\n" // store failure code in res 102 | "3:" 103 | :"=r"(res):"0"(res):"memory","%eax"); 104 | return res; 105 | } 106 | 107 | /*! 108 | * Attempt to commit/end transaction 109 | */ 110 | inline static void __TBB_machine_end_transaction() 111 | { 112 | __asm__ volatile (".byte 0x0F; .byte 0x01; .byte 0xD5" :::"memory"); // XEND 113 | } 114 | 115 | /* 116 | * aborts with code 0xFF (lock already held) 117 | */ 118 | inline static void __TBB_machine_transaction_conflict_abort() 119 | { 120 | __asm__ volatile (".byte 0xC6; .byte 0xF8; .byte 0xFF" :::"memory"); 121 | } 122 | 123 | #endif /* __TBB_TSX_INTRINSICS_PRESENT */ 124 | -------------------------------------------------------------------------------- /include/tbb/machine/windows_intel64.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_windows_intel64_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_windows_intel64_H 26 | 27 | #define __TBB_WORDSIZE 8 28 | #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 29 | 30 | #include 31 | #include "msvc_ia32_common.h" 32 | 33 | //TODO: Use _InterlockedXXX16 intrinsics for 2 byte operations 34 | #if !__INTEL_COMPILER 35 | #pragma intrinsic(_InterlockedOr64) 36 | #pragma intrinsic(_InterlockedAnd64) 37 | #pragma intrinsic(_InterlockedCompareExchange) 38 | #pragma intrinsic(_InterlockedCompareExchange64) 39 | #pragma intrinsic(_InterlockedExchangeAdd) 40 | #pragma intrinsic(_InterlockedExchangeAdd64) 41 | #pragma intrinsic(_InterlockedExchange) 42 | #pragma intrinsic(_InterlockedExchange64) 43 | #endif /* !(__INTEL_COMPILER) */ 44 | 45 | #if __INTEL_COMPILER && (__INTEL_COMPILER < 1100) 46 | #define __TBB_compiler_fence() __asm { __asm nop } 47 | #define __TBB_full_memory_fence() __asm { __asm mfence } 48 | #elif _MSC_VER >= 1300 || __INTEL_COMPILER 49 | #pragma intrinsic(_ReadWriteBarrier) 50 | #pragma intrinsic(_mm_mfence) 51 | #define __TBB_compiler_fence() _ReadWriteBarrier() 52 | #define __TBB_full_memory_fence() _mm_mfence() 53 | #endif 54 | 55 | #define __TBB_control_consistency_helper() __TBB_compiler_fence() 56 | #define __TBB_acquire_consistency_helper() __TBB_compiler_fence() 57 | #define __TBB_release_consistency_helper() __TBB_compiler_fence() 58 | 59 | // ATTENTION: if you ever change argument types in machine-specific primitives, 60 | // please take care of atomic_word<> specializations in tbb/atomic.h 61 | extern "C" { 62 | __int8 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp1 (volatile void *ptr, __int8 value, __int8 comparand ); 63 | __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd1 (volatile void *ptr, __int8 addend ); 64 | __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore1 (volatile void *ptr, __int8 value ); 65 | __int16 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp2 (volatile void *ptr, __int16 value, __int16 comparand ); 66 | __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd2 (volatile void *ptr, __int16 addend ); 67 | __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore2 (volatile void *ptr, __int16 value ); 68 | } 69 | 70 | inline long __TBB_machine_cmpswp4 (volatile void *ptr, __int32 value, __int32 comparand ) { 71 | return _InterlockedCompareExchange( (long*)ptr, value, comparand ); 72 | } 73 | inline long __TBB_machine_fetchadd4 (volatile void *ptr, __int32 addend ) { 74 | return _InterlockedExchangeAdd( (long*)ptr, addend ); 75 | } 76 | inline long __TBB_machine_fetchstore4 (volatile void *ptr, __int32 value ) { 77 | return _InterlockedExchange( (long*)ptr, value ); 78 | } 79 | 80 | inline __int64 __TBB_machine_cmpswp8 (volatile void *ptr, __int64 value, __int64 comparand ) { 81 | return _InterlockedCompareExchange64( (__int64*)ptr, value, comparand ); 82 | } 83 | inline __int64 __TBB_machine_fetchadd8 (volatile void *ptr, __int64 addend ) { 84 | return _InterlockedExchangeAdd64( (__int64*)ptr, addend ); 85 | } 86 | inline __int64 __TBB_machine_fetchstore8 (volatile void *ptr, __int64 value ) { 87 | return _InterlockedExchange64( (__int64*)ptr, value ); 88 | } 89 | 90 | #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1 91 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 92 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 93 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 94 | 95 | inline void __TBB_machine_OR( volatile void *operand, intptr_t addend ) { 96 | _InterlockedOr64((__int64*)operand, addend); 97 | } 98 | 99 | inline void __TBB_machine_AND( volatile void *operand, intptr_t addend ) { 100 | _InterlockedAnd64((__int64*)operand, addend); 101 | } 102 | 103 | #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V) 104 | #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V) 105 | 106 | -------------------------------------------------------------------------------- /include/tbb/blocked_range3d.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_blocked_range3d_H 22 | #define __TBB_blocked_range3d_H 23 | 24 | #include "tbb_stddef.h" 25 | #include "blocked_range.h" 26 | 27 | namespace tbb { 28 | 29 | //! A 3-dimensional range that models the Range concept. 30 | /** @ingroup algorithms */ 31 | template 32 | class blocked_range3d { 33 | public: 34 | //! Type for size of an iteration range 35 | typedef blocked_range page_range_type; 36 | typedef blocked_range row_range_type; 37 | typedef blocked_range col_range_type; 38 | 39 | private: 40 | page_range_type my_pages; 41 | row_range_type my_rows; 42 | col_range_type my_cols; 43 | 44 | public: 45 | 46 | blocked_range3d( PageValue page_begin, PageValue page_end, 47 | RowValue row_begin, RowValue row_end, 48 | ColValue col_begin, ColValue col_end ) : 49 | my_pages(page_begin,page_end), 50 | my_rows(row_begin,row_end), 51 | my_cols(col_begin,col_end) 52 | { 53 | } 54 | 55 | blocked_range3d( PageValue page_begin, PageValue page_end, typename page_range_type::size_type page_grainsize, 56 | RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize, 57 | ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) : 58 | my_pages(page_begin,page_end,page_grainsize), 59 | my_rows(row_begin,row_end,row_grainsize), 60 | my_cols(col_begin,col_end,col_grainsize) 61 | { 62 | } 63 | 64 | //! True if range is empty 65 | bool empty() const { 66 | // Yes, it is a logical OR here, not AND. 67 | return my_pages.empty() || my_rows.empty() || my_cols.empty(); 68 | } 69 | 70 | //! True if range is divisible into two pieces. 71 | bool is_divisible() const { 72 | return my_pages.is_divisible() || my_rows.is_divisible() || my_cols.is_divisible(); 73 | } 74 | 75 | blocked_range3d( blocked_range3d& r, split ) : 76 | my_pages(r.my_pages), 77 | my_rows(r.my_rows), 78 | my_cols(r.my_cols) 79 | { 80 | split split_obj; 81 | do_split(r, split_obj); 82 | } 83 | 84 | #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES 85 | //! Static field to support proportional split 86 | static const bool is_divisible_in_proportion = true; 87 | 88 | blocked_range3d( blocked_range3d& r, proportional_split& proportion ) : 89 | my_pages(r.my_pages), 90 | my_rows(r.my_rows), 91 | my_cols(r.my_cols) 92 | { 93 | do_split(r, proportion); 94 | } 95 | #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */ 96 | 97 | template 98 | void do_split( blocked_range3d& r, Split& split_obj) 99 | { 100 | if ( my_pages.size()*double(my_rows.grainsize()) < my_rows.size()*double(my_pages.grainsize()) ) { 101 | if ( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) { 102 | my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj); 103 | } else { 104 | my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj); 105 | } 106 | } else { 107 | if ( my_pages.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_pages.grainsize()) ) { 108 | my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj); 109 | } else { 110 | my_pages.my_begin = page_range_type::do_split(r.my_pages, split_obj); 111 | } 112 | } 113 | } 114 | 115 | //! The pages of the iteration space 116 | const page_range_type& pages() const {return my_pages;} 117 | 118 | //! The rows of the iteration space 119 | const row_range_type& rows() const {return my_rows;} 120 | 121 | //! The columns of the iteration space 122 | const col_range_type& cols() const {return my_cols;} 123 | 124 | }; 125 | 126 | } // namespace tbb 127 | 128 | #endif /* __TBB_blocked_range3d_H */ 129 | -------------------------------------------------------------------------------- /include/tbb/tick_count.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_tick_count_H 22 | #define __TBB_tick_count_H 23 | 24 | #include "tbb_stddef.h" 25 | 26 | #if _WIN32||_WIN64 27 | #include "machine/windows_api.h" 28 | #elif __linux__ 29 | #include 30 | #else /* generic Unix */ 31 | #include 32 | #endif /* (choice of OS) */ 33 | 34 | namespace tbb { 35 | 36 | //! Absolute timestamp 37 | /** @ingroup timing */ 38 | class tick_count { 39 | public: 40 | //! Relative time interval. 41 | class interval_t { 42 | long long value; 43 | explicit interval_t( long long value_ ) : value(value_) {} 44 | public: 45 | //! Construct a time interval representing zero time duration 46 | interval_t() : value(0) {}; 47 | 48 | //! Construct a time interval representing sec seconds time duration 49 | explicit interval_t( double sec ); 50 | 51 | //! Return the length of a time interval in seconds 52 | double seconds() const; 53 | 54 | friend class tbb::tick_count; 55 | 56 | //! Extract the intervals from the tick_counts and subtract them. 57 | friend interval_t operator-( const tick_count& t1, const tick_count& t0 ); 58 | 59 | //! Add two intervals. 60 | friend interval_t operator+( const interval_t& i, const interval_t& j ) { 61 | return interval_t(i.value+j.value); 62 | } 63 | 64 | //! Subtract two intervals. 65 | friend interval_t operator-( const interval_t& i, const interval_t& j ) { 66 | return interval_t(i.value-j.value); 67 | } 68 | 69 | //! Accumulation operator 70 | interval_t& operator+=( const interval_t& i ) {value += i.value; return *this;} 71 | 72 | //! Subtraction operator 73 | interval_t& operator-=( const interval_t& i ) {value -= i.value; return *this;} 74 | private: 75 | static long long ticks_per_second(){ 76 | #if _WIN32||_WIN64 77 | LARGE_INTEGER qpfreq; 78 | int rval = QueryPerformanceFrequency(&qpfreq); 79 | __TBB_ASSERT_EX(rval, "QueryPerformanceFrequency returned zero"); 80 | return static_cast(qpfreq.QuadPart); 81 | #elif __linux__ 82 | return static_cast(1E9); 83 | #else /* generic Unix */ 84 | return static_cast(1E6); 85 | #endif /* (choice of OS) */ 86 | } 87 | }; 88 | 89 | //! Construct an absolute timestamp initialized to zero. 90 | tick_count() : my_count(0) {}; 91 | 92 | //! Return current time. 93 | static tick_count now(); 94 | 95 | //! Subtract two timestamps to get the time interval between 96 | friend interval_t operator-( const tick_count& t1, const tick_count& t0 ); 97 | 98 | //! Return the resolution of the clock in seconds per tick. 99 | static double resolution() { return 1.0 / interval_t::ticks_per_second(); } 100 | 101 | private: 102 | long long my_count; 103 | }; 104 | 105 | inline tick_count tick_count::now() { 106 | tick_count result; 107 | #if _WIN32||_WIN64 108 | LARGE_INTEGER qpcnt; 109 | int rval = QueryPerformanceCounter(&qpcnt); 110 | __TBB_ASSERT_EX(rval, "QueryPerformanceCounter failed"); 111 | result.my_count = qpcnt.QuadPart; 112 | #elif __linux__ 113 | struct timespec ts; 114 | int status = clock_gettime( CLOCK_REALTIME, &ts ); 115 | __TBB_ASSERT_EX( status==0, "CLOCK_REALTIME not supported" ); 116 | result.my_count = static_cast(1000000000UL)*static_cast(ts.tv_sec) + static_cast(ts.tv_nsec); 117 | #else /* generic Unix */ 118 | struct timeval tv; 119 | int status = gettimeofday(&tv, NULL); 120 | __TBB_ASSERT_EX( status==0, "gettimeofday failed" ); 121 | result.my_count = static_cast(1000000)*static_cast(tv.tv_sec) + static_cast(tv.tv_usec); 122 | #endif /*(choice of OS) */ 123 | return result; 124 | } 125 | 126 | inline tick_count::interval_t::interval_t( double sec ) { 127 | value = static_cast(sec*interval_t::ticks_per_second()); 128 | } 129 | 130 | inline tick_count::interval_t operator-( const tick_count& t1, const tick_count& t0 ) { 131 | return tick_count::interval_t( t1.my_count-t0.my_count ); 132 | } 133 | 134 | inline double tick_count::interval_t::seconds() const { 135 | return value*tick_count::resolution(); 136 | } 137 | 138 | } // namespace tbb 139 | 140 | #endif /* __TBB_tick_count_H */ 141 | -------------------------------------------------------------------------------- /include/tbb/internal/_x86_eliding_mutex_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB__x86_eliding_mutex_impl_H 22 | #define __TBB__x86_eliding_mutex_impl_H 23 | 24 | #ifndef __TBB_spin_mutex_H 25 | #error Do not #include this internal file directly; use public TBB headers instead. 26 | #endif 27 | 28 | #if ( __TBB_x86_32 || __TBB_x86_64 ) 29 | 30 | namespace tbb { 31 | namespace interface7 { 32 | namespace internal { 33 | 34 | template 35 | class padded_mutex; 36 | 37 | //! An eliding lock that occupies a single byte. 38 | /** A x86_eliding_mutex is an HLE-enabled spin mutex. It is recommended to 39 | put the mutex on a cache line that is not shared by the data it protects. 40 | It should be used for locking short critical sections where the lock is 41 | contended but the data it protects are not. If zero-initialized, the 42 | mutex is considered unheld. 43 | @ingroup synchronization */ 44 | class x86_eliding_mutex : tbb::internal::mutex_copy_deprecated_and_disabled { 45 | //! 0 if lock is released, 1 if lock is acquired. 46 | __TBB_atomic_flag flag; 47 | 48 | friend class padded_mutex; 49 | 50 | public: 51 | //! Construct unacquired lock. 52 | /** Equivalent to zero-initialization of *this. */ 53 | x86_eliding_mutex() : flag(0) {} 54 | 55 | // bug in gcc 3.x.x causes syntax error in spite of the friend declaration above. 56 | // Make the scoped_lock public in that case. 57 | #if __TBB_USE_X86_ELIDING_MUTEX || __TBB_GCC_VERSION < 40000 58 | #else 59 | // by default we will not provide the scoped_lock interface. The user 60 | // should use the padded version of the mutex. scoped_lock is used in 61 | // padded_mutex template. 62 | private: 63 | #endif 64 | // scoped_lock in padded_mutex<> is the interface to use. 65 | //! Represents acquisition of a mutex. 66 | class scoped_lock : tbb::internal::no_copy { 67 | private: 68 | //! Points to currently held mutex, or NULL if no lock is held. 69 | x86_eliding_mutex* my_mutex; 70 | 71 | public: 72 | //! Construct without acquiring a mutex. 73 | scoped_lock() : my_mutex(NULL) {} 74 | 75 | //! Construct and acquire lock on a mutex. 76 | scoped_lock( x86_eliding_mutex& m ) : my_mutex(NULL) { acquire(m); } 77 | 78 | //! Acquire lock. 79 | void acquire( x86_eliding_mutex& m ) { 80 | __TBB_ASSERT( !my_mutex, "already holding a lock" ); 81 | 82 | my_mutex=&m; 83 | my_mutex->lock(); 84 | } 85 | 86 | //! Try acquiring lock (non-blocking) 87 | /** Return true if lock acquired; false otherwise. */ 88 | bool try_acquire( x86_eliding_mutex& m ) { 89 | __TBB_ASSERT( !my_mutex, "already holding a lock" ); 90 | 91 | bool result = m.try_lock(); 92 | if( result ) { 93 | my_mutex = &m; 94 | } 95 | return result; 96 | } 97 | 98 | //! Release lock 99 | void release() { 100 | __TBB_ASSERT( my_mutex, "release on scoped_lock that is not holding a lock" ); 101 | 102 | my_mutex->unlock(); 103 | my_mutex = NULL; 104 | } 105 | 106 | //! Destroy lock. If holding a lock, releases the lock first. 107 | ~scoped_lock() { 108 | if( my_mutex ) { 109 | release(); 110 | } 111 | } 112 | }; 113 | #if __TBB_USE_X86_ELIDING_MUTEX || __TBB_GCC_VERSION < 40000 114 | #else 115 | public: 116 | #endif /* __TBB_USE_X86_ELIDING_MUTEX */ 117 | 118 | // Mutex traits 119 | static const bool is_rw_mutex = false; 120 | static const bool is_recursive_mutex = false; 121 | static const bool is_fair_mutex = false; 122 | 123 | // ISO C++0x compatibility methods 124 | 125 | //! Acquire lock 126 | void lock() { 127 | __TBB_LockByteElided(flag); 128 | } 129 | 130 | //! Try acquiring lock (non-blocking) 131 | /** Return true if lock acquired; false otherwise. */ 132 | bool try_lock() { 133 | return __TBB_TryLockByteElided(flag); 134 | } 135 | 136 | //! Release lock 137 | void unlock() { 138 | __TBB_UnlockByteElided( flag ); 139 | } 140 | }; // end of x86_eliding_mutex 141 | 142 | } // namespace internal 143 | } // namespace interface7 144 | } // namespace tbb 145 | 146 | #endif /* ( __TBB_x86_32 || __TBB_x86_64 ) */ 147 | 148 | #endif /* __TBB__x86_eliding_mutex_impl_H */ 149 | -------------------------------------------------------------------------------- /include/tbb/machine/macos_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_macos_common_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_macos_common_H 26 | 27 | #include 28 | #define __TBB_Yield() sched_yield() 29 | 30 | // __TBB_HardwareConcurrency 31 | 32 | #include 33 | #include 34 | 35 | static inline int __TBB_macos_available_cpu() { 36 | int name[2] = {CTL_HW, HW_AVAILCPU}; 37 | int ncpu; 38 | size_t size = sizeof(ncpu); 39 | sysctl( name, 2, &ncpu, &size, NULL, 0 ); 40 | return ncpu; 41 | } 42 | 43 | #define __TBB_HardwareConcurrency() __TBB_macos_available_cpu() 44 | 45 | #ifndef __TBB_full_memory_fence 46 | // TBB has not recognized the architecture (none of the architecture abstraction 47 | // headers was included). 48 | #define __TBB_UnknownArchitecture 1 49 | #endif 50 | 51 | #if __TBB_UnknownArchitecture 52 | // Implementation of atomic operations based on OS provided primitives 53 | #include 54 | 55 | static inline int64_t __TBB_machine_cmpswp8_OsX(volatile void *ptr, int64_t value, int64_t comparand) 56 | { 57 | __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for OS X* atomics"); 58 | int64_t* address = (int64_t*)ptr; 59 | while( !OSAtomicCompareAndSwap64Barrier(comparand, value, address) ){ 60 | #if __TBB_WORDSIZE==8 61 | int64_t snapshot = *address; 62 | #else 63 | int64_t snapshot = OSAtomicAdd64( 0, address ); 64 | #endif 65 | if( snapshot!=comparand ) return snapshot; 66 | } 67 | return comparand; 68 | } 69 | 70 | #define __TBB_machine_cmpswp8 __TBB_machine_cmpswp8_OsX 71 | 72 | #endif /* __TBB_UnknownArchitecture */ 73 | 74 | #if __TBB_UnknownArchitecture 75 | 76 | #ifndef __TBB_WORDSIZE 77 | #define __TBB_WORDSIZE 4 78 | #endif 79 | 80 | #ifdef __TBB_ENDIANNESS 81 | // Already determined based on hardware architecture. 82 | #elif __BIG_ENDIAN__ 83 | #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG 84 | #elif __LITTLE_ENDIAN__ 85 | #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 86 | #else 87 | #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED 88 | #endif 89 | 90 | /** As this generic implementation has absolutely no information about underlying 91 | hardware, its performance most likely will be sub-optimal because of full memory 92 | fence usages where a more lightweight synchronization means (or none at all) 93 | could suffice. Thus if you use this header to enable TBB on a new platform, 94 | consider forking it and relaxing below helpers as appropriate. **/ 95 | #define __TBB_control_consistency_helper() OSMemoryBarrier() 96 | #define __TBB_acquire_consistency_helper() OSMemoryBarrier() 97 | #define __TBB_release_consistency_helper() OSMemoryBarrier() 98 | #define __TBB_full_memory_fence() OSMemoryBarrier() 99 | 100 | static inline int32_t __TBB_machine_cmpswp4(volatile void *ptr, int32_t value, int32_t comparand) 101 | { 102 | __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for OS X* atomics"); 103 | int32_t* address = (int32_t*)ptr; 104 | while( !OSAtomicCompareAndSwap32Barrier(comparand, value, address) ){ 105 | int32_t snapshot = *address; 106 | if( snapshot!=comparand ) return snapshot; 107 | } 108 | return comparand; 109 | } 110 | 111 | static inline int32_t __TBB_machine_fetchadd4(volatile void *ptr, int32_t addend) 112 | { 113 | __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for OS X* atomics"); 114 | return OSAtomicAdd32Barrier(addend, (int32_t*)ptr) - addend; 115 | } 116 | 117 | static inline int64_t __TBB_machine_fetchadd8(volatile void *ptr, int64_t addend) 118 | { 119 | __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for OS X* atomics"); 120 | return OSAtomicAdd64Barrier(addend, (int64_t*)ptr) - addend; 121 | } 122 | 123 | #define __TBB_USE_GENERIC_PART_WORD_CAS 1 124 | #define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD 1 125 | #define __TBB_USE_GENERIC_FETCH_STORE 1 126 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 127 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 128 | #if __TBB_WORDSIZE == 4 129 | #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1 130 | #endif 131 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 132 | 133 | #endif /* __TBB_UnknownArchitecture */ 134 | -------------------------------------------------------------------------------- /include/tbb/machine/linux_intel64.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_linux_intel64_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_linux_intel64_H 26 | 27 | #include 28 | #include "gcc_ia32_common.h" 29 | 30 | #define __TBB_WORDSIZE 8 31 | #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 32 | 33 | #define __TBB_compiler_fence() __asm__ __volatile__("": : :"memory") 34 | #define __TBB_control_consistency_helper() __TBB_compiler_fence() 35 | #define __TBB_acquire_consistency_helper() __TBB_compiler_fence() 36 | #define __TBB_release_consistency_helper() __TBB_compiler_fence() 37 | 38 | #ifndef __TBB_full_memory_fence 39 | #define __TBB_full_memory_fence() __asm__ __volatile__("mfence": : :"memory") 40 | #endif 41 | 42 | #define __TBB_MACHINE_DEFINE_ATOMICS(S,T,X) \ 43 | static inline T __TBB_machine_cmpswp##S (volatile void *ptr, T value, T comparand ) \ 44 | { \ 45 | T result; \ 46 | \ 47 | __asm__ __volatile__("lock\ncmpxchg" X " %2,%1" \ 48 | : "=a"(result), "=m"(*(volatile T*)ptr) \ 49 | : "q"(value), "0"(comparand), "m"(*(volatile T*)ptr) \ 50 | : "memory"); \ 51 | return result; \ 52 | } \ 53 | \ 54 | static inline T __TBB_machine_fetchadd##S(volatile void *ptr, T addend) \ 55 | { \ 56 | T result; \ 57 | __asm__ __volatile__("lock\nxadd" X " %0,%1" \ 58 | : "=r"(result),"=m"(*(volatile T*)ptr) \ 59 | : "0"(addend), "m"(*(volatile T*)ptr) \ 60 | : "memory"); \ 61 | return result; \ 62 | } \ 63 | \ 64 | static inline T __TBB_machine_fetchstore##S(volatile void *ptr, T value) \ 65 | { \ 66 | T result; \ 67 | __asm__ __volatile__("lock\nxchg" X " %0,%1" \ 68 | : "=r"(result),"=m"(*(volatile T*)ptr) \ 69 | : "0"(value), "m"(*(volatile T*)ptr) \ 70 | : "memory"); \ 71 | return result; \ 72 | } \ 73 | 74 | __TBB_MACHINE_DEFINE_ATOMICS(1,int8_t,"") 75 | __TBB_MACHINE_DEFINE_ATOMICS(2,int16_t,"") 76 | __TBB_MACHINE_DEFINE_ATOMICS(4,int32_t,"") 77 | __TBB_MACHINE_DEFINE_ATOMICS(8,int64_t,"q") 78 | 79 | #undef __TBB_MACHINE_DEFINE_ATOMICS 80 | 81 | static inline void __TBB_machine_or( volatile void *ptr, uint64_t value ) { 82 | __asm__ __volatile__("lock\norq %1,%0" : "=m"(*(volatile uint64_t*)ptr) : "r"(value), "m"(*(volatile uint64_t*)ptr) : "memory"); 83 | } 84 | 85 | static inline void __TBB_machine_and( volatile void *ptr, uint64_t value ) { 86 | __asm__ __volatile__("lock\nandq %1,%0" : "=m"(*(volatile uint64_t*)ptr) : "r"(value), "m"(*(volatile uint64_t*)ptr) : "memory"); 87 | } 88 | 89 | #define __TBB_AtomicOR(P,V) __TBB_machine_or(P,V) 90 | #define __TBB_AtomicAND(P,V) __TBB_machine_and(P,V) 91 | 92 | #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1 93 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 94 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 95 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 96 | 97 | -------------------------------------------------------------------------------- /include/tbb/machine/windows_ia32.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_windows_ia32_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_windows_ia32_H 26 | 27 | #include "msvc_ia32_common.h" 28 | 29 | #define __TBB_WORDSIZE 4 30 | #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 31 | 32 | #if __INTEL_COMPILER && (__INTEL_COMPILER < 1100) 33 | #define __TBB_compiler_fence() __asm { __asm nop } 34 | #define __TBB_full_memory_fence() __asm { __asm mfence } 35 | #elif _MSC_VER >= 1300 || __INTEL_COMPILER 36 | #pragma intrinsic(_ReadWriteBarrier) 37 | #pragma intrinsic(_mm_mfence) 38 | #define __TBB_compiler_fence() _ReadWriteBarrier() 39 | #define __TBB_full_memory_fence() _mm_mfence() 40 | #else 41 | #error Unsupported compiler - need to define __TBB_{control,acquire,release}_consistency_helper to support it 42 | #endif 43 | 44 | #define __TBB_control_consistency_helper() __TBB_compiler_fence() 45 | #define __TBB_acquire_consistency_helper() __TBB_compiler_fence() 46 | #define __TBB_release_consistency_helper() __TBB_compiler_fence() 47 | 48 | #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) 49 | // Workaround for overzealous compiler warnings in /Wp64 mode 50 | #pragma warning (push) 51 | #pragma warning (disable: 4244 4267) 52 | #endif 53 | 54 | extern "C" { 55 | __int64 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp8 (volatile void *ptr, __int64 value, __int64 comparand ); 56 | __int64 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd8 (volatile void *ptr, __int64 addend ); 57 | __int64 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore8 (volatile void *ptr, __int64 value ); 58 | void __TBB_EXPORTED_FUNC __TBB_machine_store8 (volatile void *ptr, __int64 value ); 59 | __int64 __TBB_EXPORTED_FUNC __TBB_machine_load8 (const volatile void *ptr); 60 | } 61 | 62 | //TODO: use _InterlockedXXX intrinsics as they available since VC 2005 63 | #define __TBB_MACHINE_DEFINE_ATOMICS(S,T,U,A,C) \ 64 | static inline T __TBB_machine_cmpswp##S ( volatile void * ptr, U value, U comparand ) { \ 65 | T result; \ 66 | volatile T *p = (T *)ptr; \ 67 | __asm \ 68 | { \ 69 | __asm mov edx, p \ 70 | __asm mov C , value \ 71 | __asm mov A , comparand \ 72 | __asm lock cmpxchg [edx], C \ 73 | __asm mov result, A \ 74 | } \ 75 | return result; \ 76 | } \ 77 | \ 78 | static inline T __TBB_machine_fetchadd##S ( volatile void * ptr, U addend ) { \ 79 | T result; \ 80 | volatile T *p = (T *)ptr; \ 81 | __asm \ 82 | { \ 83 | __asm mov edx, p \ 84 | __asm mov A, addend \ 85 | __asm lock xadd [edx], A \ 86 | __asm mov result, A \ 87 | } \ 88 | return result; \ 89 | }\ 90 | \ 91 | static inline T __TBB_machine_fetchstore##S ( volatile void * ptr, U value ) { \ 92 | T result; \ 93 | volatile T *p = (T *)ptr; \ 94 | __asm \ 95 | { \ 96 | __asm mov edx, p \ 97 | __asm mov A, value \ 98 | __asm lock xchg [edx], A \ 99 | __asm mov result, A \ 100 | } \ 101 | return result; \ 102 | } 103 | 104 | 105 | __TBB_MACHINE_DEFINE_ATOMICS(1, __int8, __int8, al, cl) 106 | __TBB_MACHINE_DEFINE_ATOMICS(2, __int16, __int16, ax, cx) 107 | __TBB_MACHINE_DEFINE_ATOMICS(4, ptrdiff_t, ptrdiff_t, eax, ecx) 108 | 109 | #undef __TBB_MACHINE_DEFINE_ATOMICS 110 | 111 | static inline void __TBB_machine_OR( volatile void *operand, __int32 addend ) { 112 | __asm 113 | { 114 | mov eax, addend 115 | mov edx, [operand] 116 | lock or [edx], eax 117 | } 118 | } 119 | 120 | static inline void __TBB_machine_AND( volatile void *operand, __int32 addend ) { 121 | __asm 122 | { 123 | mov eax, addend 124 | mov edx, [operand] 125 | lock and [edx], eax 126 | } 127 | } 128 | 129 | #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V) 130 | #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V) 131 | 132 | //TODO: Check if it possible and profitable for IA-32 architecture on (Linux and Windows) 133 | //to use of 64-bit load/store via floating point registers together with full fence 134 | //for sequentially consistent load/store, instead of CAS. 135 | #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1 136 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 137 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 138 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 139 | 140 | 141 | #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) 142 | #pragma warning (pop) 143 | #endif // warnings 4244, 4267 are back 144 | 145 | -------------------------------------------------------------------------------- /include/tbb/cache_aligned_allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_cache_aligned_allocator_H 22 | #define __TBB_cache_aligned_allocator_H 23 | 24 | #include 25 | #include "tbb_stddef.h" 26 | #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 27 | #include // std::forward 28 | #endif 29 | 30 | namespace tbb { 31 | 32 | //! @cond INTERNAL 33 | namespace internal { 34 | //! Cache/sector line size. 35 | /** @ingroup memory_allocation */ 36 | size_t __TBB_EXPORTED_FUNC NFS_GetLineSize(); 37 | 38 | //! Allocate memory on cache/sector line boundary. 39 | /** @ingroup memory_allocation */ 40 | void* __TBB_EXPORTED_FUNC NFS_Allocate( size_t n_element, size_t element_size, void* hint ); 41 | 42 | //! Free memory allocated by NFS_Allocate. 43 | /** Freeing a NULL pointer is allowed, but has no effect. 44 | @ingroup memory_allocation */ 45 | void __TBB_EXPORTED_FUNC NFS_Free( void* ); 46 | } 47 | //! @endcond 48 | 49 | #if _MSC_VER && !defined(__INTEL_COMPILER) 50 | // Workaround for erroneous "unreferenced parameter" warning in method destroy. 51 | #pragma warning (push) 52 | #pragma warning (disable: 4100) 53 | #endif 54 | 55 | //! Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5 56 | /** The members are ordered the same way they are in section 20.4.1 57 | of the ISO C++ standard. 58 | @ingroup memory_allocation */ 59 | template 60 | class cache_aligned_allocator { 61 | public: 62 | typedef typename internal::allocator_type::value_type value_type; 63 | typedef value_type* pointer; 64 | typedef const value_type* const_pointer; 65 | typedef value_type& reference; 66 | typedef const value_type& const_reference; 67 | typedef size_t size_type; 68 | typedef ptrdiff_t difference_type; 69 | template struct rebind { 70 | typedef cache_aligned_allocator other; 71 | }; 72 | 73 | cache_aligned_allocator() throw() {} 74 | cache_aligned_allocator( const cache_aligned_allocator& ) throw() {} 75 | template cache_aligned_allocator(const cache_aligned_allocator&) throw() {} 76 | 77 | pointer address(reference x) const {return &x;} 78 | const_pointer address(const_reference x) const {return &x;} 79 | 80 | //! Allocate space for n objects, starting on a cache/sector line. 81 | pointer allocate( size_type n, const void* hint=0 ) { 82 | // The "hint" argument is always ignored in NFS_Allocate thus const_cast shouldn't hurt 83 | return pointer(internal::NFS_Allocate( n, sizeof(value_type), const_cast(hint) )); 84 | } 85 | 86 | //! Free block of memory that starts on a cache line 87 | void deallocate( pointer p, size_type ) { 88 | internal::NFS_Free(p); 89 | } 90 | 91 | //! Largest value for which method allocate might succeed. 92 | size_type max_size() const throw() { 93 | return (~size_t(0)-internal::NFS_MaxLineSize)/sizeof(value_type); 94 | } 95 | 96 | //! Copy-construct value at location pointed to by p. 97 | #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 98 | template 99 | void construct(U *p, Args&&... args) 100 | { ::new((void *)p) U(std::forward(args)...); } 101 | #else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 102 | #if __TBB_CPP11_RVALUE_REF_PRESENT 103 | void construct( pointer p, value_type&& value ) {::new((void*)(p)) value_type(std::move(value));} 104 | #endif 105 | void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);} 106 | #endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 107 | 108 | //! Destroy value at location pointed to by p. 109 | void destroy( pointer p ) {p->~value_type();} 110 | }; 111 | 112 | #if _MSC_VER && !defined(__INTEL_COMPILER) 113 | #pragma warning (pop) 114 | #endif // warning 4100 is back 115 | 116 | //! Analogous to std::allocator, as defined in ISO C++ Standard, Section 20.4.1 117 | /** @ingroup memory_allocation */ 118 | template<> 119 | class cache_aligned_allocator { 120 | public: 121 | typedef void* pointer; 122 | typedef const void* const_pointer; 123 | typedef void value_type; 124 | template struct rebind { 125 | typedef cache_aligned_allocator other; 126 | }; 127 | }; 128 | 129 | template 130 | inline bool operator==( const cache_aligned_allocator&, const cache_aligned_allocator& ) {return true;} 131 | 132 | template 133 | inline bool operator!=( const cache_aligned_allocator&, const cache_aligned_allocator& ) {return false;} 134 | 135 | } // namespace tbb 136 | 137 | #endif /* __TBB_cache_aligned_allocator_H */ 138 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/TestCppBehaviour.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Collections; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | using System.Diagnostics; 8 | 9 | 10 | public class CppBehaviour : MonoBehaviour 11 | { 12 | [DllImport("CppScriptCore")] 13 | public static extern void cpsCoreInitialize(); 14 | 15 | internal IntPtr this_cpp; 16 | 17 | public CppBehaviour() 18 | { 19 | cpsCoreInitialize(); 20 | } 21 | 22 | 23 | #if UNITY_EDITOR 24 | [MenuItem ("Assets/Reload DLL")] 25 | static void ReloadDll() 26 | { 27 | #if UNITY_EDITOR_WIN 28 | System.Diagnostics.Process p = new Process(); 29 | p.StartInfo.FileName = "build.bat"; 30 | p.Start(); 31 | #endif 32 | } 33 | #endif // UNITY_EDITOR 34 | } 35 | 36 | 37 | public class TestCppBehaviour : CppBehaviour 38 | { 39 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 40 | public extern void ctor(); 41 | 42 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 43 | public extern void dtor(); 44 | 45 | 46 | 47 | Vector3 v3value; 48 | 49 | 50 | void Awake() 51 | { 52 | v3value = new Vector3(1.0f, 2.0f, 3.0f); 53 | ctor(); 54 | } 55 | 56 | void OnDestroy() 57 | { 58 | dtor(); 59 | } 60 | 61 | 62 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 63 | public extern void Start(); 64 | 65 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 66 | public extern void Update(); 67 | 68 | 69 | //[MethodImplAttribute(MethodImplOptions.InternalCall)] 70 | //public extern void BeforeAsyncUpdate(); 71 | 72 | //[MethodImplAttribute(MethodImplOptions.InternalCall)] 73 | //public extern void AsyncUpdate(); 74 | 75 | //[MethodImplAttribute(MethodImplOptions.InternalCall)] 76 | //public extern void AfterAsyncUpdate(); 77 | 78 | 79 | 80 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 81 | public extern void test1(Vector3[] a); 82 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 83 | public extern void test2(string s); 84 | 85 | 86 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 87 | public extern int memfn1(float a1); 88 | 89 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 90 | public extern int memfn2(float a1, Vector2 a2); 91 | 92 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 93 | public extern int memfn3(float a1, Vector2 a2, Vector3 a3); 94 | 95 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 96 | public extern int memfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4); 97 | 98 | 99 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 100 | public extern int cmemfn1(float a1); 101 | 102 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 103 | public extern int cmemfn2(float a1, Vector2 a2); 104 | 105 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 106 | public extern int cmemfn3(float a1, Vector2 a2, Vector3 a3); 107 | 108 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 109 | public extern int cmemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4); 110 | 111 | 112 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 113 | public extern int smemfn1(float a1); 114 | 115 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 116 | public extern int smemfn2(float a1, Vector2 a2); 117 | 118 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 119 | public extern int smemfn3(float a1, Vector2 a2, Vector3 a3); 120 | 121 | [MethodImplAttribute(MethodImplOptions.InternalCall)] 122 | public extern int smemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4); 123 | 124 | 125 | T TestTemplateMethod() where T : struct 126 | { 127 | UnityEngine.Debug.Log("TestTemplateMethod()"); 128 | return new T(); 129 | } 130 | 131 | void ThisFunctionWillBeCalledFromCpp() 132 | { 133 | UnityEngine.Debug.Log("ThisFunctionWillBeCalledFromCpp()"); 134 | 135 | Vector3[] v3array = new Vector3[] { 136 | Vector3.one * 1.0f, 137 | Vector3.one * 2.0f, 138 | Vector3.one * 3.0f, 139 | }; 140 | test1(v3array); 141 | test2("hogehoge"); 142 | 143 | //Vector3 v3 = ReturnVector3(); 144 | //UnityEngine.Debug.Log("v3: "+v3.x+", "+v3.y+", "+v3.z); 145 | 146 | float f = 1.0f; 147 | Vector2 v2 = new Vector2(0.0f, 1.0f); 148 | Vector3 v3 = new Vector3(0.0f, 1.0f, 2.0f); 149 | Vector4 v4 = new Vector4(0.0f, 1.0f, 2.0f, 3.0f); 150 | 151 | //test1(10, 20, 30, 40); 152 | //test2(1.0f, v2); 153 | 154 | memfn1(f); 155 | //UnityEngine.Debug.Log("memfn1: " + f); 156 | memfn2(f, v2); 157 | //UnityEngine.Debug.Log("memfn2: " + v2.x + ", " + v2.y); 158 | memfn3(f, v2, v3); 159 | //UnityEngine.Debug.Log("memfn3: " + v3.x + ", " + v3.y + ", " + v3.z); 160 | memfn4(f, v2, v3, v4); 161 | //UnityEngine.Debug.Log("memfn4: " + v4.x + ", " + v4.y + ", " + v4.z + ", " + v4.w); 162 | 163 | cmemfn1(f); 164 | //UnityEngine.Debug.Log("cmemfn1: " + f); 165 | cmemfn2(f, v2); 166 | //UnityEngine.Debug.Log("cmemfn2: " + v2.x + ", " + v2.y); 167 | cmemfn3(f, v2, v3); 168 | //UnityEngine.Debug.Log("cmemfn3: " + v3.x + ", " + v3.y + ", " + v3.z); 169 | cmemfn4(f, v2, v3, v4); 170 | //UnityEngine.Debug.Log("cmemfn4: " + v4.x + ", " + v4.y + ", " + v4.z + ", " + v4.w); 171 | 172 | smemfn1(f); 173 | //UnityEngine.Debug.Log("smemfn1: " + f); 174 | smemfn2(f, v2); 175 | //UnityEngine.Debug.Log("smemfn2: " + v2.x + ", " + v2.y); 176 | smemfn3(f, v2, v3); 177 | //UnityEngine.Debug.Log("smemfn3: " + v3.x + ", " + v3.y + ", " + v3.z); 178 | smemfn4(f, v2, v3, v4); 179 | //UnityEngine.Debug.Log("smemfn4: " + v4.x + ", " + v4.y + ", " + v4.z + ", " + v4.w); 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /include/tbb/queuing_rw_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_queuing_rw_mutex_H 22 | #define __TBB_queuing_rw_mutex_H 23 | 24 | #include "tbb_config.h" 25 | 26 | #if !TBB_USE_EXCEPTIONS && _MSC_VER 27 | // Suppress "C++ exception handler used, but unwind semantics are not enabled" warning in STL headers 28 | #pragma warning (push) 29 | #pragma warning (disable: 4530) 30 | #endif 31 | 32 | #include 33 | 34 | #if !TBB_USE_EXCEPTIONS && _MSC_VER 35 | #pragma warning (pop) 36 | #endif 37 | 38 | #include "atomic.h" 39 | #include "tbb_profiling.h" 40 | 41 | namespace tbb { 42 | 43 | //! Queuing reader-writer mutex with local-only spinning. 44 | /** Adapted from Krieger, Stumm, et al. pseudocode at 45 | http://www.eecg.toronto.edu/parallel/pubs_abs.html#Krieger_etal_ICPP93 46 | @ingroup synchronization */ 47 | class queuing_rw_mutex : internal::mutex_copy_deprecated_and_disabled { 48 | public: 49 | //! Construct unacquired mutex. 50 | queuing_rw_mutex() { 51 | q_tail = NULL; 52 | #if TBB_USE_THREADING_TOOLS 53 | internal_construct(); 54 | #endif 55 | } 56 | 57 | //! Destructor asserts if the mutex is acquired, i.e. q_tail is non-NULL 58 | ~queuing_rw_mutex() { 59 | #if TBB_USE_ASSERT 60 | __TBB_ASSERT( !q_tail, "destruction of an acquired mutex"); 61 | #endif 62 | } 63 | 64 | //! The scoped locking pattern 65 | /** It helps to avoid the common problem of forgetting to release lock. 66 | It also nicely provides the "node" for queuing locks. */ 67 | class scoped_lock: internal::no_copy { 68 | //! Initialize fields to mean "no lock held". 69 | void initialize() { 70 | my_mutex = NULL; 71 | #if TBB_USE_ASSERT 72 | my_state = 0xFF; // Set to invalid state 73 | internal::poison_pointer(my_next); 74 | internal::poison_pointer(my_prev); 75 | #endif /* TBB_USE_ASSERT */ 76 | } 77 | 78 | public: 79 | //! Construct lock that has not acquired a mutex. 80 | /** Equivalent to zero-initialization of *this. */ 81 | scoped_lock() {initialize();} 82 | 83 | //! Acquire lock on given mutex. 84 | scoped_lock( queuing_rw_mutex& m, bool write=true ) { 85 | initialize(); 86 | acquire(m,write); 87 | } 88 | 89 | //! Release lock (if lock is held). 90 | ~scoped_lock() { 91 | if( my_mutex ) release(); 92 | } 93 | 94 | //! Acquire lock on given mutex. 95 | void acquire( queuing_rw_mutex& m, bool write=true ); 96 | 97 | //! Acquire lock on given mutex if free (i.e. non-blocking) 98 | bool try_acquire( queuing_rw_mutex& m, bool write=true ); 99 | 100 | //! Release lock. 101 | void release(); 102 | 103 | //! Upgrade reader to become a writer. 104 | /** Returns whether the upgrade happened without releasing and re-acquiring the lock */ 105 | bool upgrade_to_writer(); 106 | 107 | //! Downgrade writer to become a reader. 108 | bool downgrade_to_reader(); 109 | 110 | private: 111 | //! The pointer to the mutex owned, or NULL if not holding a mutex. 112 | queuing_rw_mutex* my_mutex; 113 | 114 | //! The pointer to the previous and next competitors for a mutex 115 | scoped_lock *__TBB_atomic my_prev, *__TBB_atomic my_next; 116 | 117 | typedef unsigned char state_t; 118 | 119 | //! State of the request: reader, writer, active reader, other service states 120 | atomic my_state; 121 | 122 | //! The local spin-wait variable 123 | /** Corresponds to "spin" in the pseudocode but inverted for the sake of zero-initialization */ 124 | unsigned char __TBB_atomic my_going; 125 | 126 | //! A tiny internal lock 127 | unsigned char my_internal_lock; 128 | 129 | //! Acquire the internal lock 130 | void acquire_internal_lock(); 131 | 132 | //! Try to acquire the internal lock 133 | /** Returns true if lock was successfully acquired. */ 134 | bool try_acquire_internal_lock(); 135 | 136 | //! Release the internal lock 137 | void release_internal_lock(); 138 | 139 | //! Wait for internal lock to be released 140 | void wait_for_release_of_internal_lock(); 141 | 142 | //! A helper function 143 | void unblock_or_wait_on_internal_lock( uintptr_t ); 144 | }; 145 | 146 | void __TBB_EXPORTED_METHOD internal_construct(); 147 | 148 | // Mutex traits 149 | static const bool is_rw_mutex = true; 150 | static const bool is_recursive_mutex = false; 151 | static const bool is_fair_mutex = true; 152 | 153 | private: 154 | //! The last competitor requesting the lock 155 | atomic q_tail; 156 | 157 | }; 158 | 159 | __TBB_DEFINE_PROFILING_SET_NAME(queuing_rw_mutex) 160 | 161 | } // namespace tbb 162 | 163 | #endif /* __TBB_queuing_rw_mutex_H */ 164 | -------------------------------------------------------------------------------- /include/tbb/machine/gcc_generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_machine_gcc_generic_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_machine_gcc_generic_H 26 | 27 | #include 28 | #include 29 | 30 | #define __TBB_WORDSIZE __SIZEOF_POINTER__ 31 | 32 | #if __TBB_GCC_64BIT_ATOMIC_BUILTINS_BROKEN 33 | #define __TBB_64BIT_ATOMICS 0 34 | #endif 35 | 36 | /** FPU control setting not available for non-Intel architectures on Android **/ 37 | #if __ANDROID__ && __TBB_generic_arch 38 | #define __TBB_CPU_CTL_ENV_PRESENT 0 39 | #endif 40 | 41 | // __BYTE_ORDER__ is used in accordance with http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html, 42 | // but __BIG_ENDIAN__ or __LITTLE_ENDIAN__ may be more commonly found instead. 43 | #if __BIG_ENDIAN__ || (defined(__BYTE_ORDER__) && __BYTE_ORDER__==__ORDER_BIG_ENDIAN__) 44 | #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG 45 | #elif __LITTLE_ENDIAN__ || (defined(__BYTE_ORDER__) && __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) 46 | #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 47 | #elif defined(__BYTE_ORDER__) 48 | #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED 49 | #else 50 | #define __TBB_ENDIANNESS __TBB_ENDIAN_DETECT 51 | #endif 52 | 53 | /** As this generic implementation has absolutely no information about underlying 54 | hardware, its performance most likely will be sub-optimal because of full memory 55 | fence usages where a more lightweight synchronization means (or none at all) 56 | could suffice. Thus if you use this header to enable TBB on a new platform, 57 | consider forking it and relaxing below helpers as appropriate. **/ 58 | #define __TBB_acquire_consistency_helper() __sync_synchronize() 59 | #define __TBB_release_consistency_helper() __sync_synchronize() 60 | #define __TBB_full_memory_fence() __sync_synchronize() 61 | #define __TBB_control_consistency_helper() __sync_synchronize() 62 | 63 | #define __TBB_MACHINE_DEFINE_ATOMICS(S,T) \ 64 | inline T __TBB_machine_cmpswp##S( volatile void *ptr, T value, T comparand ) { \ 65 | return __sync_val_compare_and_swap(reinterpret_cast(ptr),comparand,value); \ 66 | } \ 67 | \ 68 | inline T __TBB_machine_fetchadd##S( volatile void *ptr, T value ) { \ 69 | return __sync_fetch_and_add(reinterpret_cast(ptr),value); \ 70 | } \ 71 | 72 | __TBB_MACHINE_DEFINE_ATOMICS(1,int8_t) 73 | __TBB_MACHINE_DEFINE_ATOMICS(2,int16_t) 74 | __TBB_MACHINE_DEFINE_ATOMICS(4,int32_t) 75 | __TBB_MACHINE_DEFINE_ATOMICS(8,int64_t) 76 | 77 | #undef __TBB_MACHINE_DEFINE_ATOMICS 78 | 79 | namespace tbb{ namespace internal { namespace gcc_builtins { 80 | inline int clz(unsigned int x){ return __builtin_clz(x);}; 81 | inline int clz(unsigned long int x){ return __builtin_clzl(x);}; 82 | inline int clz(unsigned long long int x){ return __builtin_clzll(x);}; 83 | }}} 84 | //gcc __builtin_clz builtin count _number_ of leading zeroes 85 | static inline intptr_t __TBB_machine_lg( uintptr_t x ) { 86 | return sizeof(x)*8 - tbb::internal::gcc_builtins::clz(x) -1 ; 87 | } 88 | 89 | static inline void __TBB_machine_or( volatile void *ptr, uintptr_t addend ) { 90 | __sync_fetch_and_or(reinterpret_cast(ptr),addend); 91 | } 92 | 93 | static inline void __TBB_machine_and( volatile void *ptr, uintptr_t addend ) { 94 | __sync_fetch_and_and(reinterpret_cast(ptr),addend); 95 | } 96 | 97 | 98 | typedef unsigned char __TBB_Flag; 99 | 100 | typedef __TBB_atomic __TBB_Flag __TBB_atomic_flag; 101 | 102 | inline bool __TBB_machine_try_lock_byte( __TBB_atomic_flag &flag ) { 103 | return __sync_lock_test_and_set(&flag,1)==0; 104 | } 105 | 106 | inline void __TBB_machine_unlock_byte( __TBB_atomic_flag &flag ) { 107 | __sync_lock_release(&flag); 108 | } 109 | 110 | // Machine specific atomic operations 111 | #define __TBB_AtomicOR(P,V) __TBB_machine_or(P,V) 112 | #define __TBB_AtomicAND(P,V) __TBB_machine_and(P,V) 113 | 114 | #define __TBB_TryLockByte __TBB_machine_try_lock_byte 115 | #define __TBB_UnlockByte __TBB_machine_unlock_byte 116 | 117 | // Definition of other functions 118 | #define __TBB_Log2(V) __TBB_machine_lg(V) 119 | 120 | #define __TBB_USE_GENERIC_FETCH_STORE 1 121 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 122 | #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 123 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 124 | 125 | #if __TBB_WORDSIZE==4 126 | #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1 127 | #endif 128 | 129 | #if __TBB_x86_32 || __TBB_x86_64 130 | #include "gcc_itsx.h" 131 | #endif 132 | -------------------------------------------------------------------------------- /TestScene/Assets/CppScripts/TestCppBehaviour.cpp: -------------------------------------------------------------------------------- 1 | #include "CppBehaviour.h" 2 | #include "monoAPI.h" 3 | #include 4 | #include 5 | 6 | 7 | class TestCppBehaviour : public CppBehaviour 8 | { 9 | typedef CppBehaviour super; 10 | public: 11 | TestCppBehaviour(cpsObject o); 12 | virtual ~TestCppBehaviour(); 13 | 14 | void Start(); 15 | void Update(); 16 | 17 | void test1(cpsArray a); 18 | void test2(cpsString str); 19 | 20 | int memfn1(float a1); 21 | int memfn2(float a1, Vector2 a2); 22 | int memfn3(float a1, Vector2 a2, Vector3 a3); 23 | int memfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4); 24 | int cmemfn1(float a1) const; 25 | int cmemfn2(float a1, Vector2 a2) const; 26 | int cmemfn3(float a1, Vector2 a2, Vector3 a3) const; 27 | int cmemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4) const; 28 | static int smemfn1(float a1); 29 | static int smemfn2(float a1, Vector2 a2); 30 | static int smemfn3(float a1, Vector2 a2, Vector3 a3); 31 | static int smemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4); 32 | 33 | private: 34 | Transform trans; 35 | int m_frame; 36 | Vector3 *m_v3v; 37 | }; 38 | 39 | 40 | 41 | cpsDefineEntryPoint() 42 | 43 | #define cpsCurrentClass TestCppBehaviour 44 | cpsExportClass() 45 | cpsExportMethod(Start) 46 | cpsExportMethod(Update) 47 | cpsExportMethod(test1) 48 | cpsExportMethod(test2) 49 | cpsExportMethod(memfn1) 50 | cpsExportMethod(memfn2) 51 | cpsExportMethod(memfn3) 52 | cpsExportMethod(memfn4) 53 | cpsExportMethod(cmemfn1) 54 | cpsExportMethod(cmemfn2) 55 | cpsExportMethod(cmemfn3) 56 | cpsExportMethod(cmemfn4) 57 | cpsExportMethod(smemfn1) 58 | cpsExportMethod(smemfn2) 59 | cpsExportMethod(smemfn3) 60 | cpsExportMethod(smemfn4) 61 | #undef cpsCurrentClass 62 | 63 | 64 | 65 | 66 | TestCppBehaviour::TestCppBehaviour(cpsObject o) 67 | : super(o) 68 | , m_frame(0) 69 | , m_v3v(cpsGetFieldValuePtr(o, "v3value")) 70 | { 71 | cpsDebugPrint("TestCppBehaviour::TestCppBehaviour()\n"); 72 | } 73 | 74 | TestCppBehaviour::~TestCppBehaviour() 75 | { 76 | cpsDebugPrint("TestCppBehaviour:~TestCppBehaviour()\n"); 77 | } 78 | 79 | 80 | void TestCppBehaviour::Start() 81 | { 82 | cpsDebugPrint("TestCppBehaviour::Start()\n"); 83 | trans = GetComponent(); 84 | 85 | cpsDumpClassStructure(cpsTypeinfo()); 86 | cpsDumpClassStructure(cpsTypeinfo()); 87 | cpsDumpClassStructure(cpsTypeinfo()); 88 | cpsDumpClassStructure(cpsTypeinfo()); 89 | cpsDumpClassStructure(cpsTypeinfo()); 90 | cpsDumpClassStructure(cpsTypeinfo()); 91 | } 92 | 93 | void TestCppBehaviour::Update() 94 | { 95 | if (++m_frame % 120 == 0) { 96 | //// crash test 97 | //*(int*)nullptr = 0; 98 | 99 | cpsDebugPrint("TestCppBehaviour::Update()\n"); 100 | cpsDebugPrint("name: %s\n", trans.get_name().toUTF8()); 101 | if (cpsMethod method = findMethod("ThisFunctionWillBeCalledFromCpp")) { 102 | method.invoke(*this, nullptr); 103 | } 104 | 105 | { 106 | m_v3v->x += 1.0f; 107 | m_v3v->y += 2.0f; 108 | m_v3v->z += 3.0f; 109 | } 110 | { 111 | Vector3 pos = trans.get_position(); 112 | pos.x += 0.1f; 113 | pos.y += 0.1f; 114 | pos.z += 0.1f; 115 | trans.set_position(pos); 116 | trans.Translate(Vector3(0.0f, 0.1f, 0.2f)); 117 | } 118 | } 119 | { 120 | trans.Rotate(Vector3(0.0f, 1.0f, 0.0f), 1.0f); 121 | } 122 | } 123 | 124 | 125 | void TestCppBehaviour::test1(cpsArray a) 126 | { 127 | cpsTArray v3a(a); 128 | cpsDebugPrint("TestCppBehaviour::test1()\n"); 129 | for (auto &v : v3a) { 130 | cpsDebugPrint(" {%.2f, %.2f, %.2f}\n", v.x, v.y, v.z); 131 | } 132 | } 133 | 134 | void TestCppBehaviour::test2(cpsString str) 135 | { 136 | cpsDebugPrint("TestCppBehaviour::test2()\n"); 137 | cpsDebugPrint("%s\n", str.toUTF8()); 138 | } 139 | 140 | 141 | 142 | int TestCppBehaviour::memfn1(float a1) 143 | { 144 | cpsDebugPrint("TestCppBehaviour::memfn1(%f)\n", a1); 145 | float f = (float)m_frame; 146 | return 1; 147 | } 148 | 149 | int TestCppBehaviour::memfn2(float a1, Vector2 a2) 150 | { 151 | cpsDebugPrint("TestCppBehaviour::memfn2(..., {%f, %f})\n", a2.x, a2.y); 152 | float f = (float)m_frame; 153 | return 2; 154 | } 155 | 156 | int TestCppBehaviour::memfn3(float a1, Vector2 a2, Vector3 a3) 157 | { 158 | cpsDebugPrint("TestCppBehaviour::memfn3(..., {%f, %f, %f})\n", a3.x, a3.y, a3.z); 159 | float f = (float)m_frame; 160 | return 3; 161 | } 162 | 163 | int TestCppBehaviour::memfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4) 164 | { 165 | cpsDebugPrint("TestCppBehaviour::memfn4((..., {%f, %f, %f, %f})\n", a4.x, a4.y, a4.z, a4.w); 166 | float f = (float)m_frame; 167 | return 4; 168 | } 169 | 170 | 171 | int TestCppBehaviour::cmemfn1(float a1) const 172 | { 173 | cpsDebugPrint("TestCppBehaviour::cmemfn1(%f)\n", a1); 174 | float f = (float)m_frame; 175 | return 5; 176 | } 177 | 178 | int TestCppBehaviour::cmemfn2(float a1, Vector2 a2) const 179 | { 180 | cpsDebugPrint("TestCppBehaviour::cmemfn2(..., {%f, %f})\n", a2.x, a2.y); 181 | float f = (float)m_frame; 182 | return 6; 183 | } 184 | 185 | int TestCppBehaviour::cmemfn3(float a1, Vector2 a2, Vector3 a3) const 186 | { 187 | cpsDebugPrint("TestCppBehaviour::cmemfn3(..., {%f, %f, %f})\n", a3.x, a3.y, a3.z); 188 | float f = (float)m_frame; 189 | return 7; 190 | } 191 | 192 | int TestCppBehaviour::cmemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4) const 193 | { 194 | cpsDebugPrint("TestCppBehaviour::cmemfn4((..., {%f, %f, %f, %f})\n", a4.x, a4.y, a4.z, a4.w); 195 | float f = (float)m_frame; 196 | return 8; 197 | } 198 | 199 | 200 | int TestCppBehaviour::smemfn1(float a1) 201 | { 202 | cpsDebugPrint("TestCppBehaviour::smemfn1(%f)\n", a1); 203 | return 9; 204 | } 205 | 206 | int TestCppBehaviour::smemfn2(float a1, Vector2 a2) 207 | { 208 | cpsDebugPrint("TestCppBehaviour::smemfn2(..., {%f, %f})\n", a2.x, a2.y); 209 | return 10; 210 | } 211 | 212 | int TestCppBehaviour::smemfn3(float a1, Vector2 a2, Vector3 a3) 213 | { 214 | cpsDebugPrint("TestCppBehaviour::smemfn3(..., {%f, %f, %f})\n", a3.x, a3.y, a3.z); 215 | return 11; 216 | } 217 | 218 | int TestCppBehaviour::smemfn4(float a1, Vector2 a2, Vector3 a3, Vector4 a4) 219 | { 220 | cpsDebugPrint("TestCppBehaviour::smemfn4((..., {%f, %f, %f, %f})\n", a4.x, a4.y, a4.z, a4.w); 221 | return 12; 222 | } 223 | -------------------------------------------------------------------------------- /include/tbb/machine/msvc_armv7.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #if !defined(__TBB_machine_H) || defined(__TBB_msvc_armv7_H) 22 | #error Do not #include this internal file directly; use public TBB headers instead. 23 | #endif 24 | 25 | #define __TBB_msvc_armv7_H 26 | 27 | #include 28 | #include 29 | 30 | #define __TBB_WORDSIZE 4 31 | 32 | #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED 33 | 34 | #if defined(TBB_WIN32_USE_CL_BUILTINS) 35 | // We can test this on _M_IX86 36 | #pragma intrinsic(_ReadWriteBarrier) 37 | #pragma intrinsic(_mm_mfence) 38 | #define __TBB_compiler_fence() _ReadWriteBarrier() 39 | #define __TBB_full_memory_fence() _mm_mfence() 40 | #define __TBB_control_consistency_helper() __TBB_compiler_fence() 41 | #define __TBB_acquire_consistency_helper() __TBB_compiler_fence() 42 | #define __TBB_release_consistency_helper() __TBB_compiler_fence() 43 | #else 44 | //Now __dmb(_ARM_BARRIER_SY) is used for both compiler and memory fences 45 | //This might be changed later after testing 46 | #define __TBB_compiler_fence() __dmb(_ARM_BARRIER_SY) 47 | #define __TBB_full_memory_fence() __dmb(_ARM_BARRIER_SY) 48 | #define __TBB_control_consistency_helper() __TBB_compiler_fence() 49 | #define __TBB_acquire_consistency_helper() __TBB_full_memory_fence() 50 | #define __TBB_release_consistency_helper() __TBB_full_memory_fence() 51 | #endif 52 | 53 | //-------------------------------------------------- 54 | // Compare and swap 55 | //-------------------------------------------------- 56 | 57 | /** 58 | * Atomic CAS for 32 bit values, if *ptr==comparand, then *ptr=value, returns *ptr 59 | * @param ptr pointer to value in memory to be swapped with value if *ptr==comparand 60 | * @param value value to assign *ptr to if *ptr==comparand 61 | * @param comparand value to compare with *ptr 62 | * @return value originally in memory at ptr, regardless of success 63 | */ 64 | 65 | #define __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(S,T,F) \ 66 | inline T __TBB_machine_cmpswp##S( volatile void *ptr, T value, T comparand ) { \ 67 | return _InterlockedCompareExchange##F(reinterpret_cast(ptr),value,comparand); \ 68 | } \ 69 | 70 | #define __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(S,T,F) \ 71 | inline T __TBB_machine_fetchadd##S( volatile void *ptr, T value ) { \ 72 | return _InterlockedExchangeAdd##F(reinterpret_cast(ptr),value); \ 73 | } \ 74 | 75 | __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(1,char,8) 76 | __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(2,short,16) 77 | __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(4,long,) 78 | __TBB_MACHINE_DEFINE_ATOMICS_CMPSWP(8,__int64,64) 79 | __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(4,long,) 80 | #if defined(TBB_WIN32_USE_CL_BUILTINS) 81 | // No _InterlockedExchangeAdd64 intrinsic on _M_IX86 82 | #define __TBB_64BIT_ATOMICS 0 83 | #else 84 | __TBB_MACHINE_DEFINE_ATOMICS_FETCHADD(8,__int64,64) 85 | #endif 86 | 87 | inline void __TBB_machine_pause (int32_t delay ) 88 | { 89 | while(delay>0) 90 | { 91 | __TBB_compiler_fence(); 92 | delay--; 93 | } 94 | } 95 | 96 | // API to retrieve/update FPU control setting 97 | #define __TBB_CPU_CTL_ENV_PRESENT 1 98 | 99 | namespace tbb { 100 | namespace internal { 101 | 102 | template 103 | struct machine_load_store_relaxed { 104 | static inline T load ( const volatile T& location ) { 105 | const T value = location; 106 | 107 | /* 108 | * An extra memory barrier is required for errata #761319 109 | * Please see http://infocenter.arm.com/help/topic/com.arm.doc.uan0004a 110 | */ 111 | __TBB_acquire_consistency_helper(); 112 | return value; 113 | } 114 | 115 | static inline void store ( volatile T& location, T value ) { 116 | location = value; 117 | } 118 | }; 119 | 120 | class cpu_ctl_env { 121 | private: 122 | unsigned int my_ctl; 123 | public: 124 | bool operator!=( const cpu_ctl_env& ctl ) const { return my_ctl != ctl.my_ctl; } 125 | void get_env() { my_ctl = _control87(0, 0); } 126 | void set_env() const { _control87( my_ctl, ~0U ); } 127 | }; 128 | 129 | } // namespace internal 130 | } // namespaces tbb 131 | 132 | // Machine specific atomic operations 133 | #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C) 134 | #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C) 135 | #define __TBB_Pause(V) __TBB_machine_pause(V) 136 | 137 | // Use generics for some things 138 | #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1 139 | #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 140 | #define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD 1 141 | #define __TBB_USE_GENERIC_PART_WORD_FETCH_STORE 1 142 | #define __TBB_USE_GENERIC_FETCH_STORE 1 143 | #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1 144 | #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1 145 | 146 | #if defined(TBB_WIN32_USE_CL_BUILTINS) 147 | #if !__TBB_WIN8UI_SUPPORT 148 | extern "C" __declspec(dllimport) int __stdcall SwitchToThread( void ); 149 | #define __TBB_Yield() SwitchToThread() 150 | #else 151 | #include 152 | #define __TBB_Yield() std::this_thread::yield() 153 | #endif 154 | #else 155 | #define __TBB_Yield() __yield() 156 | #endif 157 | 158 | // Machine specific atomic operations 159 | #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V) 160 | #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V) 161 | 162 | template 163 | inline void __TBB_machine_OR( T1 *operand, T2 addend ) { 164 | _InterlockedOr((long volatile *)operand, (long)addend); 165 | } 166 | 167 | template 168 | inline void __TBB_machine_AND( T1 *operand, T2 addend ) { 169 | _InterlockedAnd((long volatile *)operand, (long)addend); 170 | } 171 | 172 | -------------------------------------------------------------------------------- /include/tbb/parallel_while.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_parallel_while 22 | #define __TBB_parallel_while 23 | 24 | #include "task.h" 25 | #include 26 | 27 | namespace tbb { 28 | 29 | template 30 | class parallel_while; 31 | 32 | //! @cond INTERNAL 33 | namespace internal { 34 | 35 | template class while_task; 36 | 37 | //! For internal use only. 38 | /** Executes one iteration of a while. 39 | @ingroup algorithms */ 40 | template 41 | class while_iteration_task: public task { 42 | const Body& my_body; 43 | typename Body::argument_type my_value; 44 | /*override*/ task* execute() { 45 | my_body(my_value); 46 | return NULL; 47 | } 48 | while_iteration_task( const typename Body::argument_type& value, const Body& body ) : 49 | my_body(body), my_value(value) 50 | {} 51 | template friend class while_group_task; 52 | friend class tbb::parallel_while; 53 | }; 54 | 55 | //! For internal use only 56 | /** Unpacks a block of iterations. 57 | @ingroup algorithms */ 58 | template 59 | class while_group_task: public task { 60 | static const size_t max_arg_size = 4; 61 | const Body& my_body; 62 | size_t size; 63 | typename Body::argument_type my_arg[max_arg_size]; 64 | while_group_task( const Body& body ) : my_body(body), size(0) {} 65 | /*override*/ task* execute() { 66 | typedef while_iteration_task iteration_type; 67 | __TBB_ASSERT( size>0, NULL ); 68 | task_list list; 69 | task* t; 70 | size_t k=0; 71 | for(;;) { 72 | t = new( allocate_child() ) iteration_type(my_arg[k],my_body); 73 | if( ++k==size ) break; 74 | list.push_back(*t); 75 | } 76 | set_ref_count(int(k+1)); 77 | spawn(list); 78 | spawn_and_wait_for_all(*t); 79 | return NULL; 80 | } 81 | template friend class while_task; 82 | }; 83 | 84 | //! For internal use only. 85 | /** Gets block of iterations from a stream and packages them into a while_group_task. 86 | @ingroup algorithms */ 87 | template 88 | class while_task: public task { 89 | Stream& my_stream; 90 | const Body& my_body; 91 | empty_task& my_barrier; 92 | /*override*/ task* execute() { 93 | typedef while_group_task block_type; 94 | block_type& t = *new( allocate_additional_child_of(my_barrier) ) block_type(my_body); 95 | size_t k=0; 96 | while( my_stream.pop_if_present(t.my_arg[k]) ) { 97 | if( ++k==block_type::max_arg_size ) { 98 | // There might be more iterations. 99 | recycle_to_reexecute(); 100 | break; 101 | } 102 | } 103 | if( k==0 ) { 104 | destroy(t); 105 | return NULL; 106 | } else { 107 | t.size = k; 108 | return &t; 109 | } 110 | } 111 | while_task( Stream& stream, const Body& body, empty_task& barrier ) : 112 | my_stream(stream), 113 | my_body(body), 114 | my_barrier(barrier) 115 | {} 116 | friend class tbb::parallel_while; 117 | }; 118 | 119 | } // namespace internal 120 | //! @endcond 121 | 122 | //! Parallel iteration over a stream, with optional addition of more work. 123 | /** The Body b has the requirement: \n 124 | "b(v)" \n 125 | "b.argument_type" \n 126 | where v is an argument_type 127 | @ingroup algorithms */ 128 | template 129 | class parallel_while: internal::no_copy { 130 | public: 131 | //! Construct empty non-running parallel while. 132 | parallel_while() : my_body(NULL), my_barrier(NULL) {} 133 | 134 | //! Destructor cleans up data members before returning. 135 | ~parallel_while() { 136 | if( my_barrier ) { 137 | my_barrier->destroy(*my_barrier); 138 | my_barrier = NULL; 139 | } 140 | } 141 | 142 | //! Type of items 143 | typedef typename Body::argument_type value_type; 144 | 145 | //! Apply body.apply to each item in the stream. 146 | /** A Stream s has the requirements \n 147 | "S::value_type" \n 148 | "s.pop_if_present(value) is convertible to bool */ 149 | template 150 | void run( Stream& stream, const Body& body ); 151 | 152 | //! Add a work item while running. 153 | /** Should be executed only by body.apply or a thread spawned therefrom. */ 154 | void add( const value_type& item ); 155 | 156 | private: 157 | const Body* my_body; 158 | empty_task* my_barrier; 159 | }; 160 | 161 | template 162 | template 163 | void parallel_while::run( Stream& stream, const Body& body ) { 164 | using namespace internal; 165 | empty_task& barrier = *new( task::allocate_root() ) empty_task(); 166 | my_body = &body; 167 | my_barrier = &barrier; 168 | my_barrier->set_ref_count(2); 169 | while_task& w = *new( my_barrier->allocate_child() ) while_task( stream, body, barrier ); 170 | my_barrier->spawn_and_wait_for_all(w); 171 | my_barrier->destroy(*my_barrier); 172 | my_barrier = NULL; 173 | my_body = NULL; 174 | } 175 | 176 | template 177 | void parallel_while::add( const value_type& item ) { 178 | __TBB_ASSERT(my_barrier,"attempt to add to parallel_while that is not running"); 179 | typedef internal::while_iteration_task iteration_type; 180 | iteration_type& i = *new( task::allocate_additional_child_of(*my_barrier) ) iteration_type(item,*my_body); 181 | task::self().spawn( i ); 182 | } 183 | 184 | } // namespace 185 | 186 | #endif /* __TBB_parallel_while */ 187 | -------------------------------------------------------------------------------- /include/tbb/runtime_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_runtime_loader_H 22 | #define __TBB_runtime_loader_H 23 | 24 | #if ! TBB_PREVIEW_RUNTIME_LOADER 25 | #error Set TBB_PREVIEW_RUNTIME_LOADER to include runtime_loader.h 26 | #endif 27 | 28 | #include "tbb_stddef.h" 29 | #include 30 | 31 | #if _MSC_VER 32 | #if ! __TBB_NO_IMPLICIT_LINKAGE 33 | #ifdef _DEBUG 34 | #pragma comment( linker, "/nodefaultlib:tbb_debug.lib" ) 35 | #pragma comment( linker, "/defaultlib:tbbproxy_debug.lib" ) 36 | #else 37 | #pragma comment( linker, "/nodefaultlib:tbb.lib" ) 38 | #pragma comment( linker, "/defaultlib:tbbproxy.lib" ) 39 | #endif 40 | #endif 41 | #endif 42 | 43 | namespace tbb { 44 | 45 | namespace interface6 { 46 | 47 | //! Load TBB at runtime. 48 | /*! 49 | 50 | \b Usage: 51 | 52 | In source code: 53 | 54 | \code 55 | #include "tbb/runtime_loader.h" 56 | 57 | char const * path[] = { "/lib/ia32", NULL }; 58 | tbb::runtime_loader loader( path ); 59 | 60 | // Now use TBB. 61 | \endcode 62 | 63 | Link with \c tbbproxy.lib (or \c libtbbproxy.a) instead of \c tbb.lib (\c libtbb.dylib, 64 | \c libtbb.so). 65 | 66 | TBB library will be loaded at runtime from \c /lib/ia32 directory. 67 | 68 | \b Attention: 69 | 70 | All \c runtime_loader objects (in the same module, i.e. exe or dll) share some global state. 71 | The most noticeable piece of global state is loaded TBB library. 72 | There are some implications: 73 | 74 | - Only one TBB library can be loaded per module. 75 | 76 | - If one object has already loaded TBB library, another object will not load TBB. 77 | If the loaded TBB library is suitable for the second object, both will use TBB 78 | cooperatively, otherwise the second object will report an error. 79 | 80 | - \c runtime_loader objects will not work (correctly) in parallel due to absence of 81 | synchronization. 82 | 83 | */ 84 | 85 | class runtime_loader : tbb::internal::no_copy { 86 | 87 | public: 88 | 89 | //! Error mode constants. 90 | enum error_mode { 91 | em_status, //!< Save status of operation and continue. 92 | em_throw, //!< Throw an exception of tbb::runtime_loader::error_code type. 93 | em_abort //!< Print message to \c stderr and call \c abort(). 94 | }; // error_mode 95 | 96 | //! Error codes. 97 | enum error_code { 98 | ec_ok, //!< No errors. 99 | ec_bad_call, //!< Invalid function call (e. g. load() called when TBB is already loaded). 100 | ec_bad_arg, //!< Invalid argument passed. 101 | ec_bad_lib, //!< Invalid library found (e. g. \c TBB_runtime_version symbol not found). 102 | ec_bad_ver, //!< TBB found but version is not suitable. 103 | ec_no_lib //!< No suitable TBB library found. 104 | }; // error_code 105 | 106 | //! Initialize object but do not load TBB. 107 | runtime_loader( error_mode mode = em_abort ); 108 | 109 | //! Initialize object and load TBB. 110 | /*! 111 | See load() for details. 112 | 113 | If error mode is \c em_status, call status() to check whether TBB was loaded or not. 114 | */ 115 | runtime_loader( 116 | char const * path[], //!< List of directories to search TBB in. 117 | int min_ver = TBB_INTERFACE_VERSION, //!< Minimal suitable version of TBB. 118 | int max_ver = INT_MAX, //!< Maximal suitable version of TBB. 119 | error_mode mode = em_abort //!< Error mode for this object. 120 | ); 121 | 122 | //! Destroy object. 123 | ~runtime_loader(); 124 | 125 | //! Load TBB. 126 | /*! 127 | The method searches the directories specified in \c path[] array for the TBB library. 128 | When the library is found, it is loaded and its version is checked. If the version is 129 | not suitable, the library is unloaded, and the search continues. 130 | 131 | \b Note: 132 | 133 | For security reasons, avoid using relative directory names. For example, never load 134 | TBB from current (\c "."), parent (\c "..") or any other relative directory (like 135 | \c "lib" ). Use only absolute directory names (e. g. "/usr/local/lib"). 136 | 137 | For the same security reasons, avoid using system default directories (\c "") on 138 | Windows. (See http://www.microsoft.com/technet/security/advisory/2269637.mspx for 139 | details.) 140 | 141 | Neglecting these rules may cause your program to execute 3-rd party malicious code. 142 | 143 | \b Errors: 144 | - \c ec_bad_call - TBB already loaded by this object. 145 | - \c ec_bad_arg - \p min_ver and/or \p max_ver negative or zero, 146 | or \p min_ver > \p max_ver. 147 | - \c ec_bad_ver - TBB of unsuitable version already loaded by another object. 148 | - \c ec_no_lib - No suitable library found. 149 | */ 150 | error_code 151 | load( 152 | char const * path[], //!< List of directories to search TBB in. 153 | int min_ver = TBB_INTERFACE_VERSION, //!< Minimal suitable version of TBB. 154 | int max_ver = INT_MAX //!< Maximal suitable version of TBB. 155 | 156 | ); 157 | 158 | 159 | //! Report status. 160 | /*! 161 | If error mode is \c em_status, the function returns status of the last operation. 162 | */ 163 | error_code status(); 164 | 165 | private: 166 | 167 | error_mode const my_mode; 168 | error_code my_status; 169 | bool my_loaded; 170 | 171 | }; // class runtime_loader 172 | 173 | } // namespace interface6 174 | 175 | using interface6::runtime_loader; 176 | 177 | } // namespace tbb 178 | 179 | #endif /* __TBB_runtime_loader_H */ 180 | 181 | -------------------------------------------------------------------------------- /include/tbb/task_group.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_task_group_H 22 | #define __TBB_task_group_H 23 | 24 | #include "task.h" 25 | #include "tbb_exception.h" 26 | 27 | #if __TBB_TASK_GROUP_CONTEXT 28 | 29 | namespace tbb { 30 | 31 | namespace internal { 32 | template class task_handle_task; 33 | } 34 | 35 | class task_group; 36 | class structured_task_group; 37 | 38 | template 39 | class task_handle : internal::no_assign { 40 | template friend class internal::task_handle_task; 41 | friend class task_group; 42 | friend class structured_task_group; 43 | 44 | static const intptr_t scheduled = 0x1; 45 | 46 | F my_func; 47 | intptr_t my_state; 48 | 49 | void mark_scheduled () { 50 | // The check here is intentionally lax to avoid the impact of interlocked operation 51 | if ( my_state & scheduled ) 52 | internal::throw_exception( internal::eid_invalid_multiple_scheduling ); 53 | my_state |= scheduled; 54 | } 55 | public: 56 | task_handle( const F& f ) : my_func(f), my_state(0) {} 57 | 58 | void operator() () const { my_func(); } 59 | }; 60 | 61 | enum task_group_status { 62 | not_complete, 63 | complete, 64 | canceled 65 | }; 66 | 67 | namespace internal { 68 | 69 | template 70 | class task_handle_task : public task { 71 | task_handle& my_handle; 72 | /*override*/ task* execute() { 73 | my_handle(); 74 | return NULL; 75 | } 76 | public: 77 | task_handle_task( task_handle& h ) : my_handle(h) { h.mark_scheduled(); } 78 | }; 79 | 80 | class task_group_base : internal::no_copy { 81 | protected: 82 | empty_task* my_root; 83 | task_group_context my_context; 84 | 85 | task& owner () { return *my_root; } 86 | 87 | template 88 | task_group_status internal_run_and_wait( F& f ) { 89 | __TBB_TRY { 90 | if ( !my_context.is_group_execution_cancelled() ) 91 | f(); 92 | } __TBB_CATCH( ... ) { 93 | my_context.register_pending_exception(); 94 | } 95 | return wait(); 96 | } 97 | 98 | template 99 | void internal_run( F& f ) { 100 | owner().spawn( *new( owner().allocate_additional_child_of(*my_root) ) Task(f) ); 101 | } 102 | 103 | public: 104 | task_group_base( uintptr_t traits = 0 ) 105 | : my_context(task_group_context::bound, task_group_context::default_traits | traits) 106 | { 107 | my_root = new( task::allocate_root(my_context) ) empty_task; 108 | my_root->set_ref_count(1); 109 | } 110 | 111 | ~task_group_base() __TBB_NOEXCEPT(false) { 112 | if( my_root->ref_count() > 1 ) { 113 | bool stack_unwinding_in_progress = std::uncaught_exception(); 114 | // Always attempt to do proper cleanup to avoid inevitable memory corruption 115 | // in case of missing wait (for the sake of better testability & debuggability) 116 | if ( !is_canceling() ) 117 | cancel(); 118 | __TBB_TRY { 119 | my_root->wait_for_all(); 120 | } __TBB_CATCH (...) { 121 | task::destroy(*my_root); 122 | __TBB_RETHROW(); 123 | } 124 | task::destroy(*my_root); 125 | if ( !stack_unwinding_in_progress ) 126 | internal::throw_exception( internal::eid_missing_wait ); 127 | } 128 | else { 129 | task::destroy(*my_root); 130 | } 131 | } 132 | 133 | template 134 | void run( task_handle& h ) { 135 | internal_run< task_handle, internal::task_handle_task >( h ); 136 | } 137 | 138 | task_group_status wait() { 139 | __TBB_TRY { 140 | my_root->wait_for_all(); 141 | } __TBB_CATCH( ... ) { 142 | my_context.reset(); 143 | __TBB_RETHROW(); 144 | } 145 | if ( my_context.is_group_execution_cancelled() ) { 146 | my_context.reset(); 147 | return canceled; 148 | } 149 | return complete; 150 | } 151 | 152 | bool is_canceling() { 153 | return my_context.is_group_execution_cancelled(); 154 | } 155 | 156 | void cancel() { 157 | my_context.cancel_group_execution(); 158 | } 159 | }; // class task_group_base 160 | 161 | } // namespace internal 162 | 163 | class task_group : public internal::task_group_base { 164 | public: 165 | task_group () : task_group_base( task_group_context::concurrent_wait ) {} 166 | 167 | #if __SUNPRO_CC 168 | template 169 | void run( task_handle& h ) { 170 | internal_run< task_handle, internal::task_handle_task >( h ); 171 | } 172 | #else 173 | using task_group_base::run; 174 | #endif 175 | 176 | template 177 | void run( const F& f ) { 178 | internal_run< const F, internal::function_task >( f ); 179 | } 180 | 181 | template 182 | task_group_status run_and_wait( const F& f ) { 183 | return internal_run_and_wait( f ); 184 | } 185 | 186 | template 187 | task_group_status run_and_wait( task_handle& h ) { 188 | h.mark_scheduled(); 189 | return internal_run_and_wait< task_handle >( h ); 190 | } 191 | }; // class task_group 192 | 193 | class structured_task_group : public internal::task_group_base { 194 | public: 195 | template 196 | task_group_status run_and_wait ( task_handle& h ) { 197 | h.mark_scheduled(); 198 | return internal_run_and_wait< task_handle >( h ); 199 | } 200 | 201 | task_group_status wait() { 202 | task_group_status res = task_group_base::wait(); 203 | my_root->set_ref_count(1); 204 | return res; 205 | } 206 | }; // class structured_task_group 207 | 208 | inline 209 | bool is_current_task_group_canceling() { 210 | return task::self().is_cancelled(); 211 | } 212 | 213 | template 214 | task_handle make_task( const F& f ) { 215 | return task_handle( f ); 216 | } 217 | 218 | } // namespace tbb 219 | 220 | #endif /* __TBB_TASK_GROUP_CONTEXT */ 221 | 222 | #endif /* __TBB_task_group_H */ 223 | -------------------------------------------------------------------------------- /include/tbb/blocked_range.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Intel Corporation. All Rights Reserved. 3 | 4 | This file is part of Threading Building Blocks. Threading Building Blocks is free software; 5 | you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. Threading Building Blocks is 7 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 8 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 | See the GNU General Public License for more details. You should have received a copy of 10 | the GNU General Public License along with Threading Building Blocks; if not, write to the 11 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 12 | 13 | As a special exception, you may use this file as part of a free software library without 14 | restriction. Specifically, if other files instantiate templates or use macros or inline 15 | functions from this file, or you compile this file and link it with other files to produce 16 | an executable, this file does not by itself cause the resulting executable to be covered 17 | by the GNU General Public License. This exception does not however invalidate any other 18 | reasons why the executable file might be covered by the GNU General Public License. 19 | */ 20 | 21 | #ifndef __TBB_blocked_range_H 22 | #define __TBB_blocked_range_H 23 | 24 | #include "tbb_stddef.h" 25 | 26 | namespace tbb { 27 | 28 | /** \page range_req Requirements on range concept 29 | Class \c R implementing the concept of range must define: 30 | - \code R::R( const R& ); \endcode Copy constructor 31 | - \code R::~R(); \endcode Destructor 32 | - \code bool R::is_divisible() const; \endcode True if range can be partitioned into two subranges 33 | - \code bool R::empty() const; \endcode True if range is empty 34 | - \code R::R( R& r, split ); \endcode Split range \c r into two subranges. 35 | **/ 36 | 37 | //! A range over which to iterate. 38 | /** @ingroup algorithms */ 39 | template 40 | class blocked_range { 41 | public: 42 | //! Type of a value 43 | /** Called a const_iterator for sake of algorithms that need to treat a blocked_range 44 | as an STL container. */ 45 | typedef Value const_iterator; 46 | 47 | //! Type for size of a range 48 | typedef std::size_t size_type; 49 | 50 | //! Construct range with default-constructed values for begin and end. 51 | /** Requires that Value have a default constructor. */ 52 | blocked_range() : my_end(), my_begin() {} 53 | 54 | //! Construct range over half-open interval [begin,end), with the given grainsize. 55 | blocked_range( Value begin_, Value end_, size_type grainsize_=1 ) : 56 | my_end(end_), my_begin(begin_), my_grainsize(grainsize_) 57 | { 58 | __TBB_ASSERT( my_grainsize>0, "grainsize must be positive" ); 59 | } 60 | 61 | //! Beginning of range. 62 | const_iterator begin() const {return my_begin;} 63 | 64 | //! One past last value in range. 65 | const_iterator end() const {return my_end;} 66 | 67 | //! Size of the range 68 | /** Unspecified if end() 151 | friend class blocked_range2d; 152 | 153 | template 154 | friend class blocked_range3d; 155 | }; 156 | 157 | } // namespace tbb 158 | 159 | #endif /* __TBB_blocked_range_H */ 160 | --------------------------------------------------------------------------------