Use the __thread keyword extension when compiling with gcc on linux x86.

This commit is contained in:
Christopher Kohlhoff 2012-07-15 08:58:05 +10:00
parent 572024a782
commit baab2276d8
4 changed files with 88 additions and 0 deletions

View File

@ -109,6 +109,7 @@ nobase_include_HEADERS = \
asio/detail/impl/win_thread.ipp \
asio/detail/impl/win_tss_ptr.ipp \
asio/detail/io_control.hpp \
asio/detail/keyword_tss_ptr.hpp \
asio/detail/kqueue_reactor_fwd.hpp \
asio/detail/kqueue_reactor.hpp \
asio/detail/local_free_on_block_exit.hpp \

View File

@ -371,4 +371,15 @@
# endif // !defined(UNDER_CE)
#endif // !defined(ASIO_DISABLE_SIGNAL)
// Support for the __thread keyword extension.
#if !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
# if defined(__linux__)
# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
# if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# endif // ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
# endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
# endif // defined(__linux__)
#endif // !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
#endif // ASIO_DETAIL_CONFIG_HPP

View File

@ -0,0 +1,70 @@
//
// detail/keyword_tss_ptr.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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)
//
#ifndef ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
#define ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
class keyword_tss_ptr
: private noncopyable
{
public:
// Constructor.
keyword_tss_ptr()
{
}
// Destructor.
~keyword_tss_ptr()
{
}
// Get the value.
operator T*() const
{
return value_;
}
// Set the value.
void operator=(T* value)
{
value_ = value;
}
private:
static __thread T* value_;
};
template <typename T>
__thread T* keyword_tss_ptr<T>::value_;
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
#endif // ASIO_DETAIL_KEYWORD_TSS_PTR_HPP

View File

@ -19,6 +19,8 @@
#if !defined(BOOST_HAS_THREADS) || defined(ASIO_DISABLE_THREADS)
# include "asio/detail/null_tss_ptr.hpp"
#elif defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
# include "asio/detail/keyword_tss_ptr.hpp"
#elif defined(BOOST_WINDOWS)
# include "asio/detail/win_tss_ptr.hpp"
#elif defined(BOOST_HAS_PTHREADS)
@ -36,6 +38,8 @@ template <typename T>
class tss_ptr
#if !defined(BOOST_HAS_THREADS) || defined(ASIO_DISABLE_THREADS)
: public null_tss_ptr<T>
#elif defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
: public keyword_tss_ptr<T>
#elif defined(BOOST_WINDOWS)
: public win_tss_ptr<T>
#elif defined(BOOST_HAS_PTHREADS)
@ -47,6 +51,8 @@ public:
{
#if !defined(BOOST_HAS_THREADS) || defined(ASIO_DISABLE_THREADS)
null_tss_ptr<T>::operator=(value);
#elif defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
keyword_tss_ptr<T>::operator=(value);
#elif defined(BOOST_WINDOWS)
win_tss_ptr<T>::operator=(value);
#elif defined(BOOST_HAS_PTHREADS)