Skip to content

Commit

Permalink
Merge pull request #997 from leapmotion/fix-waitforstate
Browse files Browse the repository at this point in the history
Fix incorrect WaitForStateUpdate behavior
  • Loading branch information
hham authored Sep 20, 2016
2 parents 6155307 + d7cf23a commit b65152d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/autowiring/BasicThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ bool BasicThread::OnStart(void) {

void BasicThread::OnStop(bool graceful) {
// If we were never started, we need to set our completed flag to true
if (!m_wasStarted)
if (!m_wasStarted) {
std::lock_guard<std::mutex> lk(m_state->m_lock);
m_state->m_completed = true;
}

// State condition must be notified, in the event that anything is blocking
m_state->m_stateCondition.notify_all();

// Always invoke stop handler:
OnStop();
Expand Down
20 changes: 20 additions & 0 deletions src/autowiring/test/BasicThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,23 @@ TEST_F(BasicThreadTest, IsMainThread) {
);
ASSERT_FALSE(secondaryIsMain.get()) << "Secondary thread incorrectly identified as the main thread";
}

namespace {
class WaitsForStateUpdate :
public BasicThread
{
public:
void Run(void) override {
WaitForStateUpdate([] { return false; });
}
};
}

TEST_F(BasicThreadTest, WaitForStateUpdateExits) {
AutoRequired<WaitsForStateUpdate> wfsu;
AutoCurrentContext ctxt;
ctxt->Initiate();

ctxt->SignalShutdown();
ASSERT_TRUE(ctxt->Wait(std::chrono::seconds{ 10 }));
}

0 comments on commit b65152d

Please sign in to comment.