Fix another race condition in DynamicObject::Start.

Fixes #5330
This commit is contained in:
Gunnar Beutner 2013-12-14 07:36:49 +01:00
parent 5f54406057
commit 4563bb355f
3 changed files with 41 additions and 7 deletions

View File

@ -150,9 +150,24 @@ void DynamicObject::Register(void)
void DynamicObject::Start(void) void DynamicObject::Start(void)
{ {
ASSERT(!OwnsLock()); ASSERT(!OwnsLock());
ObjectLock olock(this);
ASSERT(!IsActive()); SetStartCalled(true);
SetActive(true); }
void DynamicObject::Activate(void)
{
ASSERT(!OwnsLock());
Start();
ASSERT(GetStartCalled());
{
ObjectLock olock(this);
ASSERT(!IsActive());
SetActive(true);
}
OnStarted(GetSelf()); OnStarted(GetSelf());
} }
@ -160,9 +175,27 @@ void DynamicObject::Start(void)
void DynamicObject::Stop(void) void DynamicObject::Stop(void)
{ {
ASSERT(!OwnsLock()); ASSERT(!OwnsLock());
ObjectLock olock(this);
ASSERT(IsActive()); SetStopCalled(true);
SetActive(false); }
void DynamicObject::Deactivate(void)
{
ASSERT(!OwnsLock());
{
ObjectLock olock(this);
if (!IsActive())
return;
SetActive(false);
}
Stop();
ASSERT(GetStopCalled());
OnStopped(GetSelf()); OnStopped(GetSelf());
} }
@ -299,8 +332,7 @@ void DynamicObject::StopObjects(void)
{ {
BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) { BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) { BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
if (object->IsActive()) object->Deactivate();
object->Stop();
} }
} }
} }

View File

@ -10,6 +10,8 @@ abstract class DynamicObject
[config] Array::Ptr domains; [config] Array::Ptr domains;
[config] Array::Ptr authorities; [config] Array::Ptr authorities;
[get_protected] bool active; [get_protected] bool active;
[get_protected] bool start_called;
[get_protected] bool stop_called;
Dictionary::Ptr authority_info; Dictionary::Ptr authority_info;
[protected] Dictionary::Ptr extensions; [protected] Dictionary::Ptr extensions;
}; };

View File

@ -337,7 +337,7 @@ bool ConfigItem::ActivateItems(bool validateOnly)
#ifdef _DEBUG #ifdef _DEBUG
Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'"); Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'");
#endif /* _DEBUG */ #endif /* _DEBUG */
upq.Enqueue(boost::bind(&DynamicObject::Start, object)); upq.Enqueue(boost::bind(&DynamicObject::Activate, object));
} }
} }