1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP
12 #define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP
14 #include <boost/compute/config.hpp>
16 #ifdef BOOST_COMPUTE_THREAD_SAFE
17 # ifdef BOOST_COMPUTE_HAVE_THREAD_LOCAL
18 // use c++11 thread local storage
19 # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \
20 thread_local type name ctor;
22 // use thread_specific_ptr from boost.thread
23 # include <boost/thread/tss.hpp>
24 # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \
25 static ::boost::thread_specific_ptr< type > BOOST_PP_CAT(name, _tls_ptr_); \
26 if(!BOOST_PP_CAT(name, _tls_ptr_).get()){ \
27 BOOST_PP_CAT(name, _tls_ptr_).reset(new type ctor); \
29 static type &name = *BOOST_PP_CAT(name, _tls_ptr_);
32 // no thread-safety, just use static
33 # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \
34 static type name ctor;
37 #endif // BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP