Skip to content

Commit 7db8680

Browse files
authored
Try to fix the potential data race in InformatonProviderImpl (#975)
* Fix potential data race in InformatonProviderImpl * Won't lock the local_callbacks entire scope Move the mutex lock into the desired block, only protect `m_` properties.
1 parent fcd3b52 commit 7db8680

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/pal/InformationProviderImpl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ namespace PAL_NS_BEGIN {
7373
// be deleted. The current design is that IPropertyChangedCallback is
7474
// not refcount'ed. Should we refcount it?
7575

76-
if (m_registeredCount > 0)
76+
std::vector<IPropertyChangedCallback*> local_callbacks;
7777
{
78-
std::vector<IPropertyChangedCallback*> local_callbacks;
78+
std::lock_guard<std::mutex> lock(m_lock);
79+
if (m_registeredCount > 0)
7980
{
80-
std::lock_guard<std::mutex> lock(m_lock);
8181
local_callbacks.insert(local_callbacks.end(), m_callbacks.begin(), m_callbacks.end());
82-
}
82+
}
83+
}
8384

84-
size_t count = local_callbacks.size();
85-
for (size_t index = 0; index < count; ++index)
85+
size_t count = local_callbacks.size();
86+
for (size_t index = 0; index < count; ++index)
87+
{
88+
IPropertyChangedCallback* cur_callback = local_callbacks[index];
89+
if (cur_callback != NULL)
8690
{
87-
IPropertyChangedCallback* cur_callback = local_callbacks[index];
88-
if (cur_callback != NULL)
89-
{
90-
cur_callback->OnChanged(propertyName, propertyValue);
91-
}
91+
cur_callback->OnChanged(propertyName, propertyValue);
9292
}
9393
}
9494
}

0 commit comments

Comments
 (0)