GitOrigin-RevId: 20f47274a3545fe85c26067a650232fa6f87cdc4
This commit is contained in:
Arseny Smirnov 2018-07-23 00:24:42 +03:00
parent 8bd8f4a136
commit a7c2a401b8

View File

@ -217,18 +217,7 @@ class Client::Impl final {
SCOPE_EXIT {
receive_lock_.exchange(false);
};
if (output_queue_ready_cnt_ == 0) {
output_queue_ready_cnt_ = output_queue_->reader_wait_nonblock();
}
if (output_queue_ready_cnt_ > 0) {
output_queue_ready_cnt_--;
return output_queue_->reader_get_unsafe();
}
if (timeout != 0) {
poll_.run(static_cast<int>(timeout * 1000));
return receive(0);
}
return {0, nullptr};
return receive_unlocked(timeout);
}
Impl(const Impl &) = delete;
@ -269,6 +258,21 @@ class Client::Impl final {
auto &event_fd = output_queue_->reader_get_event_fd();
poll_.subscribe(event_fd.get_fd(), Fd::Read);
}
Response receive_unlocked(double timeout) {
if (output_queue_ready_cnt_ == 0) {
output_queue_ready_cnt_ = output_queue_->reader_wait_nonblock();
}
if (output_queue_ready_cnt_ > 0) {
output_queue_ready_cnt_--;
return output_queue_->reader_get_unsafe();
}
if (timeout != 0) {
poll_.run(static_cast<int>(timeout * 1000));
return receive_unlocked(0);
}
return {0, nullptr};
}
};
#endif