Added TRUE_CURRENT_TIME() macro

Because CURRENT_TIME() can now be a past date if --now is used.
This commit is contained in:
John Wiegley 2009-10-28 01:17:54 -04:00
parent 559566751d
commit cc532c31aa
3 changed files with 12 additions and 11 deletions

View file

@ -393,7 +393,7 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point,
DEBUG("commodity.download", "moment = " << *moment); DEBUG("commodity.download", "moment = " << *moment);
DEBUG("commodity.download", "slip.moment = " << seconds_diff); DEBUG("commodity.download", "slip.moment = " << seconds_diff);
} else { } else {
seconds_diff = (CURRENT_TIME() - point->when).total_seconds(); seconds_diff = (TRUE_CURRENT_TIME() - point->when).total_seconds();
DEBUG("commodity.download", "slip.now = " << seconds_diff); DEBUG("commodity.download", "slip.now = " << seconds_diff);
} }

View file

@ -69,11 +69,11 @@ inline bool is_valid(const date_t& moment) {
extern optional<datetime_t> epoch; extern optional<datetime_t> epoch;
#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
#define CURRENT_TIME() \ #define TRUE_CURRENT_TIME() (boost::posix_time::microsec_clock::universal_time())
(epoch ? *epoch : boost::posix_time::microsec_clock::universal_time()) #define CURRENT_TIME() (epoch ? *epoch : TRUE_CURRENT_TIME())
#else #else
#define CURRENT_TIME() \ #define TRUE_CURRENT_TIME() (boost::posix_time::second_clock::universal_time())
(epoch ? *epoch : boost::posix_time::second_clock::universal_time()) #define CURRENT_TIME() (epoch ? *epoch : TRUE_CURRENT_TIME())
#endif #endif
#define CURRENT_DATE() \ #define CURRENT_DATE() \
(epoch ? epoch->date() : boost::gregorian::day_clock::universal_day()) (epoch ? epoch->date() : boost::gregorian::day_clock::universal_day())

View file

@ -531,14 +531,15 @@ bool logger_func(log_level_t level)
{ {
if (! logger_has_run) { if (! logger_has_run) {
logger_has_run = true; logger_has_run = true;
logger_start = CURRENT_TIME(); logger_start = TRUE_CURRENT_TIME();
IF_VERIFY() IF_VERIFY()
*_log_stream << " TIME OBJSZ MEMSZ" << std::endl; *_log_stream << " TIME OBJSZ MEMSZ" << std::endl;
} }
*_log_stream << std::right << std::setw(5) *_log_stream << std::right << std::setw(5)
<< (CURRENT_TIME() - logger_start).total_milliseconds() << "ms"; << (TRUE_CURRENT_TIME() -
logger_start).total_milliseconds() << "ms";
#if defined(VERIFY_ON) #if defined(VERIFY_ON)
IF_VERIFY() { IF_VERIFY() {
@ -616,7 +617,7 @@ struct timer_t
bool active; bool active;
timer_t(log_level_t _level, std::string _description) timer_t(log_level_t _level, std::string _description)
: level(_level), begin(CURRENT_TIME()), : level(_level), begin(TRUE_CURRENT_TIME()),
spent(time_duration(0, 0, 0, 0)), spent(time_duration(0, 0, 0, 0)),
description(_description), active(true) {} description(_description), active(true) {}
}; };
@ -637,7 +638,7 @@ void start_timer(const char * name, log_level_t lvl)
timers.insert(timer_map::value_type(name, timer_t(lvl, _log_buffer.str()))); timers.insert(timer_map::value_type(name, timer_t(lvl, _log_buffer.str())));
} else { } else {
assert((*i).second.description == _log_buffer.str()); assert((*i).second.description == _log_buffer.str());
(*i).second.begin = CURRENT_TIME(); (*i).second.begin = TRUE_CURRENT_TIME();
(*i).second.active = true; (*i).second.active = true;
} }
_log_buffer.str(""); _log_buffer.str("");
@ -657,7 +658,7 @@ void stop_timer(const char * name)
timer_map::iterator i = timers.find(name); timer_map::iterator i = timers.find(name);
assert(i != timers.end()); assert(i != timers.end());
(*i).second.spent += CURRENT_TIME() - (*i).second.begin; (*i).second.spent += TRUE_CURRENT_TIME() - (*i).second.begin;
(*i).second.active = false; (*i).second.active = false;
#if defined(VERIFY_ON) #if defined(VERIFY_ON)
@ -682,7 +683,7 @@ void finish_timer(const char * name)
time_duration spent = (*i).second.spent; time_duration spent = (*i).second.spent;
if ((*i).second.active) { if ((*i).second.active) {
spent = CURRENT_TIME() - (*i).second.begin; spent = TRUE_CURRENT_TIME() - (*i).second.begin;
(*i).second.active = false; (*i).second.active = false;
} }