-
Notifications
You must be signed in to change notification settings - Fork 149
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
Make sure the wakePend flag does not incur undefined behavior. #170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,7 +434,8 @@ bool XrdSys::IOEvents::Channel::Enable(int events, int timeout, | |
// that we cannot hold the channel mutex for this call because it may wait. | ||
// | ||
if (isLocked) chMutex.UnLock(); | ||
if (retval && !(chPollXQ->wakePend) && setTO && isLocked) chPollXQ->WakeUp(); | ||
bool isWakePend = CPP_ATOMIC_LOAD(chPollXQ->wakePend, std::memory_order_consume); | ||
if (retval && !isWakePend && setTO && isLocked) chPollXQ->WakeUp(); | ||
|
||
// All done | ||
// | ||
|
@@ -1142,7 +1143,7 @@ int XrdSys::IOEvents::Poller::TmoGet() | |
|
||
// Return the value | ||
// | ||
wakePend = false; | ||
CPP_ATOMIC_STORE(wakePend, false, std::memory_order_release); | ||
toMutex.UnLock(); | ||
return wtval; | ||
} | ||
|
@@ -1158,9 +1159,19 @@ void XrdSys::IOEvents::Poller::WakeUp() | |
// Send it off to wakeup the poller thread, but only if here is no wakeup in | ||
// progress. | ||
// | ||
// We use a mutex here because we want to produce a synchronization point - all | ||
// threads that might be interested timeouts and wakeups are going to incur a | ||
// cache bounce for the page where wakePend resides; they will see a consistent | ||
// view of the wakePend flag. For those threads, this is equivalent to | ||
// an atomic with memory_order std::memory_order_seq_cst (the strongest ordering). | ||
// However, the threads that are not interested in timeouts will not get a flush | ||
// for their copy of the wakePend page. They will still have the weaker memory | ||
// ordering of consume/release (which is guaranteed anyway on all current architectures | ||
// except for DEC Alpha). | ||
toMutex.Lock(); | ||
if (wakePend) toMutex.UnLock(); | ||
else {wakePend = true; | ||
bool isWakePend = CPP_ATOMIC_LOAD(wakePend, std::memory_order_consume); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note I eliminated the toMute locking here - I can't figure out what it'd be useful for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Brian, That bit of code that was eliminated makes it much more probable that Andy On Thu, 20 Nov 2014, Brian Bockelman wrote:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll add it back with a distilled version of your above comment. |
||
if (isWakePend) {toMutex.UnLock();} | ||
else {CPP_ATOMIC_STORE(wakePend, true, std::memory_order_release); | ||
toMutex.UnLock(); | ||
SendCmd(cmdbuff); | ||
} | ||
|
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.
It's not clear what this lock is supposed to do in the first place!