-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perf[BMQIO]: remove unnecessary function copy #483
Conversation
a512422
to
8b0c00f
Compare
@@ -758,11 +755,19 @@ void NtcChannel::processReadQueueLowWatermark( | |||
|
|||
int numNeeded = 0; | |||
{ | |||
bmqio::Channel::ReadCallback readCallback = read->callback(); | |||
const bmqio::Channel::ReadCallback& readCallback = | |||
read->callback(); | |||
|
|||
bslmt::UnLockGuard<bslmt::Mutex> unlock(&d_mutex); | |||
readCallback(bmqio::Status(), &numNeeded, &d_readCache); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bslmt::UnLockGuard<bslmt::Mutex> unlock(&d_mutex);
// !!!!!!!!! `close` might be called from another thread
readCallback(bmqio::Status(), &numNeeded, &d_readCache);
Here, we have a non-trivial thread race. In the past, we could have emptied the d_callback
of NtcRead
between these 2 lines of code. We make a copy of d_callback
before unlocking a mutex, so we don't access the empty callback. However, it means that we can send another callback from this copy after we executed close
.
My PR doesn't fix this race, so we still can send something over this callback. Instead, I make sure not to clear it from another thread, so this reference is always alive. And I also added a post-check for isComplete()
to return early.
Signed-off-by: Evgeny Malygin <[email protected]>
8b0c00f
to
699d567
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build 341 of commit 699d567 has completed with FAILURE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we can eliminate setComplete
now and use clear
instead?
Signed-off-by: Evgeny Malygin <[email protected]>
Done. Made sure that we have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build 346 of commit f0fcea3 has completed with FAILURE
IO thread should spend 7.5% (1.7 / 22.96) less cpu
Before:
After: