|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59260 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-24 16:20:58
Author: viboes
Date: 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
New Revision: 59260
URL: http://svn.boost.org/trac/boost/changeset/59260
Log:
Boost.Chrono: Version 0.3.2,
* code cleanup
* added get_reporter metafunction on stopwatch
* updated thread_clock.hpp
Text files modified:
sandbox/chrono/boost/chrono/digital_time_formatter.hpp | 24 ++++++------
sandbox/chrono/boost/chrono/process_times.hpp | 4 +-
sandbox/chrono/boost/chrono/scoped_stopclock.hpp | 2
sandbox/chrono/boost/chrono/scoped_suspend.hpp | 8 ++--
sandbox/chrono/boost/chrono/stopwatch.hpp | 6 ++
sandbox/chrono/boost/chrono/stopwatch_formatter.hpp | 28 ++++++++--------
sandbox/chrono/boost/chrono/thread_clock.hpp | 69 ++++++++++++++++++++++++++++++++-------
sandbox/chrono/boost/chrono/time_formatter.hpp | 22 ++++++------
8 files changed, 105 insertions(+), 58 deletions(-)
Modified: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -34,13 +34,13 @@
template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
class Alloc=std::allocator<CharT>
>
class basic_digital_time_formatter {
public:
-
+
typedef std::basic_string<CharT,Traits,Alloc> string_type;
typedef CharT char_type;
typedef std::basic_ostream<CharT,Traits> ostream_type;
@@ -118,7 +118,7 @@
}
}
};
-
+
namespace detail {
template <typename CharT>
struct basic_digital_time_formatter_default_format;
@@ -131,25 +131,25 @@
struct basic_digital_time_formatter_default_format<wchar_t> {
static const wchar_t* apply() {return L"%d day(s) %h:%m:%s.%n\n"; }
};
-
-#endif
+
+#endif
}
-
+
template <typename CharT,typename Traits, class Alloc>
- const typename basic_digital_time_formatter<CharT,Traits,Alloc>::char_type*
+ const typename basic_digital_time_formatter<CharT,Traits,Alloc>::char_type*
basic_digital_time_formatter<CharT,Traits,Alloc>::default_format() {
return detail::basic_digital_time_formatter_default_format<CharT>::apply();
}
template <typename CharT,typename Traits, class Alloc>
- typename basic_digital_time_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_digital_time_formatter<CharT,Traits,Alloc>::default_os() {
- return detail::default_out<CharT,Traits>::apply();
+ typename basic_digital_time_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_digital_time_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
}
typedef basic_digital_time_formatter<char> digital_time_formatter;
typedef basic_digital_time_formatter<wchar_t> wdigital_time_formatter;
-
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/process_times.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_times.hpp (original)
+++ sandbox/chrono/boost/chrono/process_times.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -48,13 +48,13 @@
process_clock::time_point user; // user cpu time
process_clock::time_point system; // system cpu time
};
-
+
static void now( durations & times,
system::error_code & ec = system::throws );
static void now( time_points & times,
system::error_code & ec = system::throws );
};
-
+
//--------------------------------------------------------------------------------------//
// process_times //
//--------------------------------------------------------------------------------------//
Modified: sandbox/chrono/boost/chrono/scoped_stopclock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/scoped_stopclock.hpp (original)
+++ sandbox/chrono/boost/chrono/scoped_stopclock.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -40,7 +40,7 @@
//--------------------------------------------------------------------------------------//
template <class Clock=process_cpu_clock, class Formatter=typename stopwatch_reporter_default_formatter<chrono::stopwatch<Clock> >::type >
- class scoped_stopclock
+ class scoped_stopclock
: public stopwatch_reporter<chrono::stopwatch<Clock>, Formatter> {
typedef stopwatch_reporter<chrono::stopwatch<Clock>, Formatter> base_type;
public:
Modified: sandbox/chrono/boost/chrono/scoped_suspend.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/scoped_suspend.hpp (original)
+++ sandbox/chrono/boost/chrono/scoped_suspend.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -15,10 +15,10 @@
namespace boost { namespace chrono {
-
+
template <class Clock>
struct is_suspendible : mpl:: false_ {};
-
+
template <class Clock>
class scoped_suspend {
public:
@@ -28,9 +28,9 @@
scoped_suspend(); // = delete;
scoped_suspend(const scoped_suspend&); // = delete;
scoped_suspend& operator=(const scoped_suspend&); // = delete;
- };
+ };
+
-
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -145,7 +145,7 @@
{
if (running_)
return clock::now( ec ) - start_ + partial_;
- else
+ else
return partial_;
}
@@ -164,6 +164,10 @@
typedef stopwatch_stopper<stopwatch<Clock> > scoped_stop;
typedef stopwatch_suspender<stopwatch<Clock> > scoped_suspend;
typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
+ template <class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock> >::type>
+ struct get_reporter {
+ typedef stopwatch_reporter<stopwatch<Clock>,Formatter > type;
+ };
typedef stopwatch_reporter<stopwatch<Clock> > reporter;
private:
Modified: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -33,8 +33,8 @@
template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
class Alloc=std::allocator<CharT>
>
class basic_stopwatch_formatter {
@@ -42,11 +42,11 @@
//~ typedef std::string string_type;
//~ typedef string_type::value_type char_type;
//~ typedef std::ostream ostream_type;
-
+
typedef std::basic_string<CharT,Traits,Alloc> string_type;
typedef CharT char_type;
typedef std::basic_ostream<CharT,Traits> ostream_type;
-
+
static ostream_type & default_os();
static const char_type* default_format();
static string_type format(const char_type* s) {
@@ -106,25 +106,25 @@
struct basic_stopwatch_formatter_default_format<wchar_t> {
static const wchar_t* apply() {return L"%ds\n"; }
};
-
-#endif
+
+#endif
}
-
+
template <typename CharT,typename Traits, class Alloc>
- const typename basic_stopwatch_formatter<CharT,Traits,Alloc>::char_type*
- basic_stopwatch_formatter<CharT,Traits,Alloc>::default_format() {
+ const typename basic_stopwatch_formatter<CharT,Traits,Alloc>::char_type*
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_format() {
return detail::basic_stopwatch_formatter_default_format<CharT>::apply();
}
-
+
template <typename CharT,typename Traits, class Alloc>
- typename basic_stopwatch_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os() {
- return detail::default_out<CharT,Traits>::apply();
+ typename basic_stopwatch_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
}
typedef basic_stopwatch_formatter<char> stopwatch_formatter;
typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
-
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/thread_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/thread_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/thread_clock.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -10,28 +10,71 @@
#ifndef BOOST_CHRONO_THREAD_CLOCK_HPP
#define BOOST_CHRONO_THREAD_CLOCK_HPP
+#include <time.h>
+#include <pthread.h>
+
+#include <boost/chrono/config.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/system/error_code.hpp>
-#include <boost/operators.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/system/system_error.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost { namespace chrono {
- class BOOST_CHRONO_DECL thread_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_real_cpu_clock> time_point;
- static const bool is_monotonic = true;
-
- static time_point now( system::error_code & ec = system::throws );
- };
-
+#if defined(BOOST_CHRONO_POSIX_API) && defined(_POSIX_THREAD_CPUTIME)
+class BOOST_CHRONO_DECL thread_clock {
+public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<thread_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( ) {
+ // get the current thread
+ pthread_t pth=pthread_self();
+ // get the clock_id associated to the current thread
+ clockid_t clock_id;
+ pthread_getcpuclockid(pth, clock_id);
+ // get the timespec associated to the thread clock
+ struct timespec ts;
+ if ( ::clock_gettime( clock_id, &ts ) )
+ {
+ boost::throw_exception(
+ system::system_error( errno, system::system_category, "chrono::thread_clock" ));
+ }
+
+ // transform to nanoseconds
+ return time_point(duration(
+ static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
+
+ }
+ static time_point now( system::error_code & ec ) {
+ // get the current thread
+ pthread_t pth=pthread_self();
+ // get the clock_id associated to the current thread
+ clockid_t clock_id;
+ pthread_getcpuclockid(pth, clock_id);
+ // get the timespec associated to the thread clock
+ struct timespec ts;
+ if ( ::clock_gettime( clock_id, &ts ) )
+ {
+ ec.assign( errno, system::system_category );
+ return time_point();
+ }
+ ec.clear();
+ // transform to nanoseconds
+ return time_point(duration(
+ static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
+
+ }
+};
+#endif
} // namespace chrono
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-#endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
+#endif // BOOST_CHRONO_THREAD_CLOCK_HPP
Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp 2010-01-24 16:20:57 EST (Sun, 24 Jan 2010)
@@ -36,8 +36,8 @@
template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
class Alloc=std::allocator<CharT>
>
class basic_time_formatter {
@@ -45,7 +45,7 @@
//~ typedef std::string string_type;
//~ typedef string_type::value_type char_type;
//~ typedef std::ostream ostream_type;
-
+
typedef std::basic_string<CharT,Traits,Alloc> string_type;
typedef CharT char_type;
typedef std::basic_ostream<CharT,Traits> ostream_type;
@@ -138,22 +138,22 @@
struct basic_time_formatter_default_format<wchar_t> {
static const wchar_t* apply() {return L"real %rs, cpu %cs (%p%), user %us, system %ss\n"; }
};
-
-#endif
+
+#endif
}
-
+
template <typename CharT,typename Traits, class Alloc>
- const typename basic_time_formatter<CharT,Traits,Alloc>::char_type*
+ const typename basic_time_formatter<CharT,Traits,Alloc>::char_type*
basic_time_formatter<CharT,Traits,Alloc>::default_format() {
return detail::basic_time_formatter_default_format<CharT>::apply();
}
template <typename CharT,typename Traits, class Alloc>
- typename basic_time_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_time_formatter<CharT,Traits,Alloc>::default_os() {
- return detail::default_out<CharT,Traits>::apply();
+ typename basic_time_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_time_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
}
-
+
typedef basic_time_formatter<char> time_formatter;
typedef basic_time_formatter<wchar_t> wtime_formatter;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk