#ifndef BOOST_THREAD_PTHREAD_ONCE_HPP #define BOOST_THREAD_PTHREAD_ONCE_HPP // once.hpp // // (C) Copyright 2007-8 Anthony Williams // (C) Copyright 2011-2012 Vicente J. Botet Escriba // // 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) #include #include #include #include namespace boost { struct once_flag { #if defined(__GNUC__) __attribute__((may_alias)) #endif uintmax_t storage; }; #define BOOST_ONCE_INIT {0} namespace thread_detail { BOOST_THREAD_DECL bool enter_once_region(once_flag& flag) BOOST_NOEXCEPT; BOOST_THREAD_DECL void commit_once_region(once_flag& flag) BOOST_NOEXCEPT; BOOST_THREAD_DECL void rollback_once_region(once_flag& flag) BOOST_NOEXCEPT; } template inline void call_once(once_flag& flag, Function f) { if (thread_detail::enter_once_region(flag)) { BOOST_TRY { f(); } BOOST_CATCH (...) { thread_detail::rollback_once_region(flag); BOOST_RETHROW } BOOST_CATCH_END thread_detail::commit_once_region(flag); } } } #include #endif