Commit 963b9f82 authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Make addObserver/removeObserver take a write lock

Summary:
As title.  These methods look like they never protected observers_ list, and relied on
the user not calling addObserver or removeObserver concurrently.  I don't see any downsides
to taking a write lock here, these methods aren't called often.

Reviewed By: davidtgoldblatt

Differential Revision: D8187184

fbshipit-source-id: dd20b809e851cc14a05aca3bc9722e0a9236665f
parent 6d02e2b5
......@@ -344,7 +344,7 @@ size_t ThreadPoolExecutor::StoppedThreadQueue::size() {
void ThreadPoolExecutor::addObserver(std::shared_ptr<Observer> o) {
{
SharedMutex::ReadHolder r{&threadListLock_};
SharedMutex::WriteHolder r{&threadListLock_};
observers_.push_back(o);
for (auto& thread : threadList_.get()) {
o->threadPreviouslyStarted(thread.get());
......@@ -357,7 +357,7 @@ void ThreadPoolExecutor::addObserver(std::shared_ptr<Observer> o) {
}
void ThreadPoolExecutor::removeObserver(std::shared_ptr<Observer> o) {
SharedMutex::ReadHolder r{&threadListLock_};
SharedMutex::WriteHolder r{&threadListLock_};
for (auto& thread : threadList_.get()) {
o->threadNotYetStopped(thread.get());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment