mirror of
https://github.com/boostorg/log.git
synced 2026-02-01 08:32:15 +00:00
Merged latest changes from trunk.
[SVN r85461]
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* \date 02.12.2007
|
||||
*
|
||||
* \brief This header is the Boost.Log library implementation, see the library documentation
|
||||
* at http://www.boost.org/libs/log/doc/log.html.
|
||||
* at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
|
||||
*/
|
||||
|
||||
#include <boost/config.hpp>
|
||||
@@ -20,12 +20,13 @@
|
||||
#if defined(BOOST_WINDOWS) && !defined(BOOST_LOG_NO_QUERY_PERFORMANCE_COUNTER)
|
||||
|
||||
#include "windows_version.hpp"
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/detail/interlocked.hpp>
|
||||
#include <boost/log/detail/config.hpp>
|
||||
#if !defined(BOOST_LOG_NO_THREADS)
|
||||
#include <boost/log/detail/locks.hpp>
|
||||
#include <boost/log/detail/spin_mutex.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <boost/log/detail/header.hpp>
|
||||
|
||||
@@ -36,18 +37,18 @@ BOOST_LOG_OPEN_NAMESPACE
|
||||
namespace attributes {
|
||||
|
||||
//! Factory implementation
|
||||
class BOOST_LOG_VISIBLE timer::impl :
|
||||
class BOOST_SYMBOL_VISIBLE timer::impl :
|
||||
public attribute::impl
|
||||
{
|
||||
private:
|
||||
#if !defined(BOOST_LOG_NO_THREADS)
|
||||
//! Synchronization mutex type
|
||||
typedef log::aux::spin_mutex mutex_type;
|
||||
typedef boost::mutex mutex_type;
|
||||
//! Synchronization mutex
|
||||
mutex_type m_Mutex;
|
||||
#endif
|
||||
//! Frequency factor for calculating duration
|
||||
uint64_t m_FrequencyFactor;
|
||||
double m_FrequencyFactor;
|
||||
//! Last value of the performance counter
|
||||
uint64_t m_LastCounter;
|
||||
//! Elapsed time duration, in microseconds
|
||||
@@ -60,7 +61,7 @@ public:
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceFrequency(&li);
|
||||
BOOST_ASSERT(li.QuadPart != 0LL);
|
||||
m_FrequencyFactor = static_cast< uint64_t >(li.QuadPart) / 1000000ULL;
|
||||
m_FrequencyFactor = 1000000.0 / static_cast< double >(li.QuadPart);
|
||||
|
||||
QueryPerformanceCounter(&li);
|
||||
m_LastCounter = static_cast< uint64_t >(li.QuadPart);
|
||||
@@ -69,43 +70,20 @@ public:
|
||||
//! The method returns the actual attribute value. It must not return NULL.
|
||||
attribute_value get_value()
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceCounter(&li);
|
||||
|
||||
uint64_t duration;
|
||||
{
|
||||
BOOST_LOG_EXPR_IF_MT(log::aux::exclusive_lock_guard< mutex_type > _(m_Mutex);)
|
||||
BOOST_LOG_EXPR_IF_MT(log::aux::exclusive_lock_guard< mutex_type > lock(m_Mutex);)
|
||||
|
||||
const uint64_t counts = static_cast< uint64_t >(li.QuadPart) - m_LastCounter;
|
||||
m_LastCounter = static_cast< uint64_t >(li.QuadPart);
|
||||
m_Duration += counts / m_FrequencyFactor;
|
||||
duration = m_Duration;
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceCounter(&li);
|
||||
const uint64_t counter = static_cast< uint64_t >(li.QuadPart);
|
||||
const uint64_t counts = counter - m_LastCounter;
|
||||
m_LastCounter = counter;
|
||||
duration = m_Duration + static_cast< uint64_t >(counts * m_FrequencyFactor);
|
||||
m_Duration = duration;
|
||||
}
|
||||
|
||||
// All these dances are needed simply to construct Boost.DateTime duration without truncating the value
|
||||
value_type res;
|
||||
if (duration < static_cast< uint64_t >((std::numeric_limits< value_type::fractional_seconds_type >::max)()))
|
||||
{
|
||||
res = value_type(0, 0, 0, static_cast< value_type::fractional_seconds_type >(
|
||||
duration * (1000000 / value_type::traits_type::ticks_per_second)));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t total_seconds = duration / 1000000ULL;
|
||||
value_type::fractional_seconds_type usec = static_cast< value_type::fractional_seconds_type >(duration % 1000000ULL);
|
||||
if (total_seconds < static_cast< uint64_t >((std::numeric_limits< value_type::sec_type >::max)()))
|
||||
{
|
||||
res = value_type(0, 0, static_cast< value_type::sec_type >(total_seconds), usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t total_hours = total_seconds / 3600ULL;
|
||||
value_type::sec_type seconds = static_cast< value_type::sec_type >(total_seconds % 3600ULL);
|
||||
res = value_type(static_cast< value_type::hour_type >(total_hours), 0, seconds, usec);
|
||||
}
|
||||
}
|
||||
|
||||
return attribute_value(new attribute_value_impl< value_type >(res));
|
||||
return attribute_value(new attribute_value_impl< value_type >(boost::posix_time::microseconds(duration)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -138,7 +116,7 @@ BOOST_LOG_OPEN_NAMESPACE
|
||||
namespace attributes {
|
||||
|
||||
//! Factory implementation
|
||||
class BOOST_LOG_VISIBLE timer::impl :
|
||||
class BOOST_SYMBOL_VISIBLE timer::impl :
|
||||
public attribute::impl
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user