Skip to content
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

Add timeout-free Barrier variant #482

Merged
merged 1 commit into from Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions autowiring/DispatchQueue.h
Expand Up @@ -200,6 +200,11 @@ class DispatchQueue {
/// </remarks>
bool Barrier(std::chrono::nanoseconds timeout);

/// <summary>
/// Identical to the timed version of Barrier, but does not time out
/// </summary>
void Barrier(void);

/// <summary>
/// Recommends a point in time to wake up to check for events
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/autowiring/DispatchQueue.cpp
Expand Up @@ -193,6 +193,21 @@ bool DispatchQueue::Barrier(std::chrono::nanoseconds timeout) {
return rv;
}

void DispatchQueue::Barrier(void) {
// Set up the lambda:
bool complete = false;
*this += [&] { complete = true; };

// Obtain the lock, wait until our variable is satisfied, which might be right away:
std::unique_lock<std::mutex> lk(m_dispatchLock);
m_queueUpdated.wait(lk, [&] { return m_aborted || complete; });
if (m_aborted)
// At this point, the dispatch queue MUST be completely run down. We have no outstanding references
// to our stack-allocated "complete" variable. Furthermore, after m_aborted is true, no further
// dispatchers are permitted to be run.
throw autowiring_error("Dispatch queue was aborted while a barrier was invoked");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be dispatch_aborted_exception? If not, what's the difference?

}

std::chrono::steady_clock::time_point
DispatchQueue::SuggestSoonestWakeupTimeUnsafe(std::chrono::steady_clock::time_point latestTime) const {
return
Expand Down
2 changes: 1 addition & 1 deletion src/autowiring/test/DispatchQueueTest.cpp
Expand Up @@ -129,4 +129,4 @@ TEST_F(DispatchQueueTest, BarrierWithAbort) {
ct->Abort();
ASSERT_EQ(std::future_status::ready, f.wait_for(std::chrono::seconds(5))) << "Barrier did not abort fast enough";
ASSERT_TRUE(*exception) << "Exception should have been thrown inside the Barrier call";
}
}