Skip to content

Commit ba35fba

Browse files
committed
Fix waits.
1 parent 436bd6a commit ba35fba

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ void ProController_SysbotBase3::replace_on_next_command(){
7676
}
7777
void ProController_SysbotBase3::wait_for_all(const Cancellable* cancellable){
7878
std::unique_lock<std::mutex> lg(m_state_lock);
79-
if (m_stopping){
80-
throw InvalidConnectionStateException();
79+
while (true){
80+
if (m_stopping){
81+
throw InvalidConnectionStateException();
82+
}
83+
if (cancellable){
84+
cancellable->throw_if_cancelled();
85+
}
86+
if (m_next_seqnum == m_next_expected_seqnum_ack){
87+
break;
88+
}
89+
m_cv.wait(lg);
8190
}
82-
m_cv.wait(lg, [this]{
83-
return m_stopping || m_next_seqnum == m_next_expected_seqnum_ack;
84-
});
8591
}
8692

8793
void ProController_SysbotBase3::on_receive_data(const void* data, size_t bytes){
@@ -194,7 +200,10 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
194200
std::unique_lock<std::mutex> lg(m_state_lock, std::adopt_lock_t());
195201

196202
// Wait until there is space.
197-
m_cv.wait(lg, [this]{
203+
m_cv.wait(lg, [this, cancellable]{
204+
if (cancellable && cancellable->cancelled()){
205+
return true;
206+
}
198207
return m_stopping || m_next_seqnum - m_next_expected_seqnum_ack < QUEUE_SIZE;
199208
});
200209

0 commit comments

Comments
 (0)