Files

99 lines
2.5 KiB
C++

// Copyright (C) 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)
#ifndef ACTIV_BOOST_THREAD_DETAIL_LOG_HPP
#define ACTIV_BOOST_THREAD_DETAIL_LOG_HPP
#include <ActivBoost/thread/detail/config.hpp>
#if defined ACTIV_BOOST_THREAD_USES_LOG
#include <ActivBoost/thread/recursive_mutex.hpp>
#include <ActivBoost/thread/lock_guard.hpp>
#if defined ACTIV_BOOST_THREAD_USES_LOG_THREAD_ID
#include <ActivBoost/thread/thread.hpp>
#endif
#include <iostream>
namespace Boost
{
namespace thread_detail
{
inline Boost::recursive_mutex& terminal_mutex()
{
static Boost::recursive_mutex mtx;
return mtx;
}
}
}
#if defined ACTIV_BOOST_THREAD_USES_LOG_THREAD_ID
#define ACTIV_BOOST_THREAD_LOG \
{ \
Boost::lock_guard<Boost::recursive_mutex> _lk_(Boost::thread_detail::terminal_mutex()); \
std::cout << Boost::this_thread::get_id() << " - "<<__FILE__<<"["<<__LINE__<<"] " <<std::dec
#else
#define ACTIV_BOOST_THREAD_LOG \
{ \
Boost::lock_guard<Boost::recursive_mutex> _lk_(Boost::thread_detail::terminal_mutex()); \
std::cout << __FILE__<<"["<<__LINE__<<"] " <<std::dec
#endif
#define ACTIV_BOOST_THREAD_END_LOG \
std::dec << std::endl; \
}
#else
namespace Boost
{
namespace thread_detail
{
struct dummy_stream_t
{
};
template <typename T>
inline dummy_stream_t const& operator<<(dummy_stream_t const& os, T)
{
return os;
}
inline dummy_stream_t const& operator<<(dummy_stream_t const& os, dummy_stream_t const&)
{
return os;
}
ACTIV_BOOST_CONSTEXPR_OR_CONST dummy_stream_t dummy_stream = {};
}
}
#ifdef ACTIV_BOOST_MSVC
#define ACTIV_BOOST_THREAD_LOG \
__pragma(warning(suppress:4127)) /* conditional expression is constant */ \
if (true) {} else Boost::thread_detail::dummy_stream
#else
#define ACTIV_BOOST_THREAD_LOG if (true) {} else Boost::thread_detail::dummy_stream
#endif
#define ACTIV_BOOST_THREAD_END_LOG Boost::thread_detail::dummy_stream
#endif
#define ACTIV_BOOST_THREAD_TRACE ACTIV_BOOST_THREAD_LOG << ACTIV_BOOST_THREAD_END_LOG
#ifdef ACTIV_BOOST_MSVC
#define ACTIV_BOOST_DETAIL_THREAD_LOG \
__pragma(warning(suppress:4127)) /* conditional expression is constant */ \
if (false) {} else std::cout << std::endl << __FILE__ << "[" << __LINE__ << "]"
#else
#define ACTIV_BOOST_DETAIL_THREAD_LOG \
if (false) {} else std::cout << std::endl << __FILE__ << "[" << __LINE__ << "]"
#endif
#endif // header