Skip to content

Commit d84848a

Browse files
committed
Add a bit of cladding around setting the concurrency provider.
1 parent 161b33f commit d84848a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Concurrency/WorkContractGroup.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ namespace Concurrency {
206206
ENTROPY_ASSERT(mainThreadSelectingCount == 0, "WorkContractGroup destroyed with threads still in selectForMainThreadExecution");
207207

208208
// Then notify the concurrency provider to remove us from active groups
209-
if (_concurrencyProvider) {
210-
_concurrencyProvider->notifyGroupDestroyed(this);
209+
{
210+
std::unique_lock<std::shared_mutex> lock(_concurrencyProviderMutex);
211+
if (_concurrencyProvider) {
212+
_concurrencyProvider->notifyGroupDestroyed(this);
213+
}
211214
}
212215
}
213216

@@ -293,8 +296,11 @@ namespace Concurrency {
293296
}
294297

295298
// Notify concurrency provider if set
296-
if (_concurrencyProvider) {
297-
_concurrencyProvider->notifyWorkAvailable(this);
299+
{
300+
std::shared_lock<std::shared_mutex> lock(_concurrencyProviderMutex);
301+
if (_concurrencyProvider) {
302+
_concurrencyProvider->notifyWorkAvailable(this);
303+
}
298304
}
299305

300306
return ScheduleResult::Scheduled;
@@ -761,6 +767,7 @@ namespace Concurrency {
761767
}
762768

763769
void WorkContractGroup::setConcurrencyProvider(IConcurrencyProvider* provider) {
770+
std::unique_lock<std::shared_mutex> lock(_concurrencyProviderMutex);
764771
_concurrencyProvider = provider;
765772
}
766773

src/Concurrency/WorkContractGroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ namespace Concurrency {
146146

147147
// Concurrency provider support
148148
IConcurrencyProvider* _concurrencyProvider = nullptr; ///< Work notification provider
149+
mutable std::shared_mutex _concurrencyProviderMutex; ///< Protects provider during setup/teardown (COLD PATH ONLY)
149150
std::list<std::function<void()>> _onCapacityAvailableCallbacks; ///< Capacity callbacks
150151
mutable std::mutex _callbackMutex; ///< Protects callback list
151152

0 commit comments

Comments
 (0)