File indexing completed on 2025-01-18 09:28:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_POSIX_GLOBAL_HPP
0012 #define BOOST_ASIO_DETAIL_POSIX_GLOBAL_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_HAS_PTHREADS)
0021
0022 #include <exception>
0023 #include <pthread.h>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030
0031 template <typename T>
0032 struct posix_global_impl
0033 {
0034
0035 static void do_init()
0036 {
0037 instance_.static_ptr_ = instance_.ptr_ = new T;
0038 }
0039
0040
0041 ~posix_global_impl()
0042 {
0043 delete static_ptr_;
0044 }
0045
0046 static ::pthread_once_t init_once_;
0047 static T* static_ptr_;
0048 static posix_global_impl instance_;
0049 T* ptr_;
0050 };
0051
0052 template <typename T>
0053 ::pthread_once_t posix_global_impl<T>::init_once_ = PTHREAD_ONCE_INIT;
0054
0055 template <typename T>
0056 T* posix_global_impl<T>::static_ptr_ = 0;
0057
0058 template <typename T>
0059 posix_global_impl<T> posix_global_impl<T>::instance_;
0060
0061 template <typename T>
0062 T& posix_global()
0063 {
0064 int result = ::pthread_once(
0065 &posix_global_impl<T>::init_once_,
0066 &posix_global_impl<T>::do_init);
0067
0068 if (result != 0)
0069 std::terminate();
0070
0071 return *posix_global_impl<T>::instance_.ptr_;
0072 }
0073
0074 }
0075 }
0076 }
0077
0078 #include <boost/asio/detail/pop_options.hpp>
0079
0080 #endif
0081
0082 #endif