MpscPollableQueue: minor optimization

GitOrigin-RevId: 9d87dafe8b91622979a73ed068fdd73c60fdff29
This commit is contained in:
Arseny Smirnov 2019-07-04 14:07:14 +02:00
parent 13627727ef
commit 1e9cefb2eb

View File

@ -29,16 +29,20 @@ class MpscPollableQueue {
return narrow_cast<int>(ready); return narrow_cast<int>(ready);
} }
event_fd_.acquire(); for (int i = 0; i < 2; i++) {
auto guard = lock_.lock(); auto guard = lock_.lock();
if (writer_vector_.empty()) { if (writer_vector_.empty()) {
wait_event_fd_ = true; if (i == 1) {
return 0; wait_event_fd_ = true;
} else { return 0;
reader_vector_.clear(); }
reader_pos_ = 0; } else {
std::swap(writer_vector_, reader_vector_); reader_vector_.clear();
return narrow_cast<int>(reader_vector_.size()); reader_pos_ = 0;
std::swap(writer_vector_, reader_vector_);
return narrow_cast<int>(reader_vector_.size());
}
event_fd_.acquire();
} }
} }
ValueType reader_get_unsafe() { ValueType reader_get_unsafe() {