Skip to content

Commit de65d7d

Browse files
committed
Fix SBB3 replace_on_next_command().
1 parent 63f28aa commit de65d7d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ProController_SysbotBase3::replace_on_next_command(){
7575
}
7676

7777
uint64_t queued = m_next_seqnum - m_next_expected_seqnum_ack;
78-
m_next_expected_seqnum_ack = m_next_seqnum;
78+
// m_next_expected_seqnum_ack = m_next_seqnum;
7979

8080
m_pending_replace = true;
8181

@@ -91,7 +91,16 @@ void ProController_SysbotBase3::replace_on_next_command(){
9191
m_logger.log("replace_on_next_command(): Command Queue Size = " + std::to_string(queued), COLOR_DARKGREEN);
9292
}
9393
void ProController_SysbotBase3::wait_for_all(const Cancellable* cancellable){
94-
std::unique_lock<std::mutex> lg(m_state_lock);
94+
std::lock_guard<std::mutex> lg0(m_issue_lock);
95+
std::unique_lock<std::mutex> lg1(m_state_lock);
96+
97+
// cout << "wait_for_all() - start" << endl;
98+
99+
if (m_stopping){
100+
throw InvalidConnectionStateException("");
101+
}
102+
this->issue_wait_for_all(cancellable);
103+
95104
while (true){
96105
if (m_stopping){
97106
throw InvalidConnectionStateException("");
@@ -102,8 +111,10 @@ void ProController_SysbotBase3::wait_for_all(const Cancellable* cancellable){
102111
if (m_next_seqnum == m_next_expected_seqnum_ack){
103112
break;
104113
}
105-
m_cv.wait(lg);
114+
m_cv.wait(lg1);
106115
}
116+
117+
// cout << "wait_for_all() - done" << endl;
107118
}
108119

109120

@@ -237,6 +248,7 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
237248
std::string message;
238249
if (m_pending_replace){
239250
m_pending_replace = false;
251+
m_next_expected_seqnum_ack = m_next_seqnum;
240252
message += "cqReplaceOnNext\r\n";
241253
}
242254

0 commit comments

Comments
 (0)