mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Adds timeout capabilities to blocking Rpc Calls (#86)
This commit is contained in:
committed by
Peter Johnson
parent
bc99d341fb
commit
0b80bd2b09
@@ -1407,7 +1407,12 @@ unsigned int Storage::CallRpc(StringRef name, StringRef params) {
|
||||
return combined_uid;
|
||||
}
|
||||
|
||||
bool Storage::GetRpcResult(bool blocking, unsigned int call_uid,
|
||||
bool Storage::GetRpcResult(bool blocking, unsigned int call_uid,
|
||||
std::string* result) {
|
||||
return GetRpcResult(blocking, call_uid, -1, result);
|
||||
}
|
||||
|
||||
bool Storage::GetRpcResult(bool blocking, unsigned int call_uid, double time_out,
|
||||
std::string* result) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
for (;;) {
|
||||
@@ -1415,7 +1420,18 @@ bool Storage::GetRpcResult(bool blocking, unsigned int call_uid,
|
||||
m_rpc_results.find(std::make_pair(call_uid >> 16, call_uid & 0xffff));
|
||||
if (i == m_rpc_results.end()) {
|
||||
if (!blocking || m_terminating) return false;
|
||||
m_rpc_results_cond.wait(lock);
|
||||
if (time_out < 0) {
|
||||
m_rpc_results_cond.wait(lock);
|
||||
} else {
|
||||
auto timeout_time = std::chrono::steady_clock::now() +
|
||||
std::chrono::duration<double>(time_out);
|
||||
while (!m_terminating) {
|
||||
auto timed_out = m_rpc_results_cond.wait_until(lock, timeout_time);
|
||||
if (timed_out == std::cv_status::timeout) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_terminating) return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user