Fix race condition in TimePeriod::Start.

Refs #5337
This commit is contained in:
Gunnar Beutner 2013-12-15 18:36:31 +01:00
parent f08bca220d
commit ff5a35b7db
2 changed files with 12 additions and 7 deletions

View File

@ -32,17 +32,20 @@ REGISTER_TYPE(TimePeriod);
static Timer::Ptr l_UpdateTimer;
INITIALIZE_ONCE(&TimePeriod::StaticInitialize);
void TimePeriod::StaticInitialize(void)
{
l_UpdateTimer = make_shared<Timer>();
l_UpdateTimer->SetInterval(300);
l_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler));
l_UpdateTimer->Start();
}
void TimePeriod::Start(void)
{
DynamicObject::Start();
if (!l_UpdateTimer) {
l_UpdateTimer = make_shared<Timer>();
l_UpdateTimer->SetInterval(300);
l_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler));
l_UpdateTimer->Start();
}
/* Pre-fill the time period for the next 24 hours. */
double now = Utility::GetTime();
UpdateRegion(now, now + 24 * 3600, true);

View File

@ -38,6 +38,8 @@ public:
DECLARE_PTR_TYPEDEFS(TimePeriod);
DECLARE_TYPENAME(TimePeriod);
static void StaticInitialize(void);
virtual void Start(void);
void UpdateRegion(double begin, double end, bool clearExisting);