Checker: Use Ptrs rather than WeakPtrs.

Fixes #3732
This commit is contained in:
Gunnar Beutner 2013-02-26 10:58:32 +01:00
parent f027f1681b
commit 45f8bfb730
4 changed files with 17 additions and 12 deletions

View File

@ -72,9 +72,9 @@ void CheckerComponent::CheckThreadProc(void)
break; break;
CheckTimeView::iterator it = idx.begin(); CheckTimeView::iterator it = idx.begin();
Service::Ptr service = it->lock(); Service::Ptr service = *it;
if (!service) { if (!service->IsRegistered()) {
idx.erase(it); idx.erase(it);
continue; continue;
} }

View File

@ -33,13 +33,8 @@ struct ServiceNextCheckExtractor
/** /**
* @threadsafety Caller must hold the mutex for the service. * @threadsafety Caller must hold the mutex for the service.
*/ */
double operator()(const Service::WeakPtr& wservice) double operator()(const Service::Ptr& service)
{ {
Service::Ptr service = wservice.lock();
if (!service)
return 0;
return service->GetNextCheck(); return service->GetNextCheck();
} }
}; };
@ -54,9 +49,9 @@ public:
typedef weak_ptr<CheckerComponent> WeakPtr; typedef weak_ptr<CheckerComponent> WeakPtr;
typedef multi_index_container< typedef multi_index_container<
Service::WeakPtr, Service::Ptr,
indexed_by< indexed_by<
ordered_unique<identity<Service::WeakPtr> >, ordered_unique<identity<Service::Ptr> >,
ordered_non_unique<ServiceNextCheckExtractor> ordered_non_unique<ServiceNextCheckExtractor>
> >
> ServiceSet; > ServiceSet;

View File

@ -33,7 +33,7 @@ signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> DynamicObjec
signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnFlushObject; signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
: m_EventSafe(false), m_ConfigTx(0) : m_EventSafe(false), m_ConfigTx(0), m_Registered(false)
{ {
RegisterAttribute("__name", Attribute_Config, &m_Name); RegisterAttribute("__name", Attribute_Config, &m_Name);
RegisterAttribute("__type", Attribute_Config, &m_Type); RegisterAttribute("__type", Attribute_Config, &m_Type);
@ -309,6 +309,11 @@ bool DynamicObject::IsAbstract(void) const
return m_Abstract; return m_Abstract;
} }
bool DynamicObject::IsRegistered(void) const
{
return m_Registered;
}
void DynamicObject::SetSource(const String& value) void DynamicObject::SetSource(const String& value)
{ {
m_Source = value; m_Source = value;
@ -572,7 +577,10 @@ void DynamicObject::OnConstructionCompleted(void)
} }
void DynamicObject::OnRegistrationCompleted(void) void DynamicObject::OnRegistrationCompleted(void)
{ } {
ObjectLock olock(this);
m_Registered = true;
}
void DynamicObject::OnAttributeChanged(const String&, const Value&) void DynamicObject::OnAttributeChanged(const String&, const Value&)
{ } { }

View File

@ -238,6 +238,7 @@ public:
bool IsLocal(void) const; bool IsLocal(void) const;
bool IsAbstract(void) const; bool IsAbstract(void) const;
bool IsRegistered(void) const;
void SetSource(const String& value); void SetSource(const String& value);
String GetSource(void) const; String GetSource(void) const;
@ -286,6 +287,7 @@ private:
Attribute<String> m_Source; Attribute<String> m_Source;
Attribute<Dictionary::Ptr> m_Methods; Attribute<Dictionary::Ptr> m_Methods;
bool m_Registered;
bool m_EventSafe; bool m_EventSafe;
static double m_CurrentTx; static double m_CurrentTx;