MpscPollableQueue: minor optimization
GitOrigin-RevId: 9d87dafe8b91622979a73ed068fdd73c60fdff29
This commit is contained in:
parent
13627727ef
commit
1e9cefb2eb
@ -29,17 +29,21 @@ 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()) {
|
||||||
|
if (i == 1) {
|
||||||
wait_event_fd_ = true;
|
wait_event_fd_ = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reader_vector_.clear();
|
reader_vector_.clear();
|
||||||
reader_pos_ = 0;
|
reader_pos_ = 0;
|
||||||
std::swap(writer_vector_, reader_vector_);
|
std::swap(writer_vector_, reader_vector_);
|
||||||
return narrow_cast<int>(reader_vector_.size());
|
return narrow_cast<int>(reader_vector_.size());
|
||||||
}
|
}
|
||||||
|
event_fd_.acquire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ValueType reader_get_unsafe() {
|
ValueType reader_get_unsafe() {
|
||||||
return std::move(reader_vector_[reader_pos_++]);
|
return std::move(reader_vector_[reader_pos_++]);
|
||||||
|
Loading…
Reference in New Issue
Block a user