#ifndef BOOST_THREAD_PREAMBLE_HPP #define BOOST_THREAD_PREAMBLE_HPP ////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Based on the threadalert library of Roland Schwarz // ////////////////////////////////////////////////////////////////////////////// #include namespace boost { class thread_preamble { public: template thread_preamble(Function inifn) : initfunc_(inifn), prev_(last_) { // the constructor is thread-safe because it is only used on // global objects which are constructed before any threads last_ = this; } class proxy { public: template proxy(Function f): func_(f) {}; proxy(const boost::function0& f): func_(f) {}; void operator()(); private: const boost::function0 func_; }; private: friend class proxy; static void func(); const boost::function0 initfunc_; static thread_preamble* last_; thread_preamble* prev_; }; } #endif