* Fix a crash that occurs when a provider is registered after the configuration object has been destroyed.
* Code review feedback.
}
CONTRACTL_END;
- return new EventPipeProvider(providerName, pCallbackFunction, pCallbackData);
+ EventPipeProvider *pProvider = NULL;
+ if (s_pConfig != NULL)
+ {
+ pProvider = s_pConfig->CreateProvider(providerName, pCallbackFunction, pCallbackData);
+ }
+
+ return pProvider;
+
}
void EventPipe::DeleteProvider(EventPipeProvider *pProvider)
else
{
// Delete the provider now.
- // NOTE: This will remove it from all of the EventPipe data structures.
- delete(pProvider);
+ if (s_pConfig != NULL)
+ {
+ s_pConfig->DeleteProvider(pProvider);
+ }
}
}
}
CONTRACTL_END;
// Create the configuration provider.
- m_pConfigProvider = EventPipe::CreateProvider(SL(s_configurationProviderName));
+ m_pConfigProvider = CreateProvider(SL(s_configurationProviderName), NULL, NULL);
// Create the metadata event.
m_pMetadataEvent = m_pConfigProvider->AddEvent(
false); /* needStack */
}
+EventPipeProvider* EventPipeConfiguration::CreateProvider(const SString &providerName, EventPipeCallback pCallbackFunction, void *pCallbackData)
+{
+ CONTRACTL
+ {
+ THROWS;
+ GC_NOTRIGGER;
+ MODE_ANY;
+ }
+ CONTRACTL_END;
+
+ // Allocate a new provider.
+ EventPipeProvider *pProvider = new EventPipeProvider(this, providerName, pCallbackFunction, pCallbackData);
+
+ // Register the provider with the configuration system.
+ RegisterProvider(*pProvider);
+
+ return pProvider;
+}
+
+void EventPipeConfiguration::DeleteProvider(EventPipeProvider *pProvider)
+{
+ CONTRACTL
+ {
+ THROWS;
+ GC_NOTRIGGER;
+ MODE_ANY;
+ PRECONDITION(pProvider != NULL);
+ }
+ CONTRACTL_END;
+
+ if (pProvider == NULL)
+ {
+ return;
+ }
+
+ // Unregister the provider.
+ UnregisterProvider(*pProvider);
+
+ // Free the provider itself.
+ delete(pProvider);
+}
+
+
bool EventPipeConfiguration::RegisterProvider(EventPipeProvider &provider)
{
CONTRACTL
// Perform initialization that cannot be performed in the constructor.
void Initialize();
+ // Create a new provider.
+ EventPipeProvider* CreateProvider(const SString &providerName, EventPipeCallback pCallbackFunction, void *pCallbackData);
+
+ // Delete a provider.
+ void DeleteProvider(EventPipeProvider *pProvider);
+
// Register a provider.
bool RegisterProvider(EventPipeProvider &provider);
#ifdef FEATURE_PERFTRACING
-EventPipeProvider::EventPipeProvider(const SString &providerName, EventPipeCallback pCallbackFunction, void *pCallbackData)
+EventPipeProvider::EventPipeProvider(EventPipeConfiguration *pConfig, const SString &providerName, EventPipeCallback pCallbackFunction, void *pCallbackData)
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
MODE_ANY;
+ PRECONDITION(pConfig != NULL);
}
CONTRACTL_END;
m_pEventList = new SList<SListElem<EventPipeEvent*>>();
m_pCallbackFunction = pCallbackFunction;
m_pCallbackData = pCallbackData;
- m_pConfig = EventPipe::GetConfiguration();
- _ASSERTE(m_pConfig != NULL);
-
- // Register the provider.
- m_pConfig->RegisterProvider(*this);
+ m_pConfig = pConfig;
}
EventPipeProvider::~EventPipeProvider()
}
CONTRACTL_END;
- // Unregister the provider.
- // This call is re-entrant.
- // NOTE: We don't use the cached event pipe configuration pointer
- // in case this runs during shutdown and the configuration has already
- // been freed.
- EventPipeConfiguration* pConfig = EventPipe::GetConfiguration();
- _ASSERTE(pConfig != NULL);
- pConfig->UnregisterProvider(*this);
-
// Free all of the events.
if(m_pEventList != NULL)
{
bool m_deleteDeferred;
// Private constructor because all providers are created through EventPipe::CreateProvider.
- EventPipeProvider(const SString &providerName, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
+ EventPipeProvider(EventPipeConfiguration *pConfig, const SString &providerName, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
public: