// This class maintains a list of outstanding content analysis requests to // process. Each request is encapsulated in one ContentAnalysisEvent. // Requests are handled in FIFO order. class RequestQueue { public: using Event = content_analysis::sdk::ContentAnalysisEvent;
// Push a new content analysis event into the queue. void push(std::unique_ptr<Event> event) {
std::lock_guard<std::mutex> lock(mutex_);
events_.push(std::move(event));
// Wake before leaving to prevent unpredicatable scheduling.
cv_.notify_one();
}
// Pop the next request from the queue, blocking if necessary until an event // is available. Returns a nullptr if the queue will produce no more // events.
std::unique_ptr<Event> pop() {
std::unique_lock<std::mutex> lock(mutex_);
while (!abort_ && events_.size() == 0)
cv_.wait(lock);
std::unique_ptr<Event> event; if (!abort_) {
event = std::move(events_.front());
events_.pop();
}
return event;
}
// Marks the queue as aborted. pop() will now return nullptr. void abort() {
std::lock_guard<std::mutex> lg(mutex_);
abort_ = true;
// Wake before leaving to prevent unpredicatable scheduling.
cv_.notify_all();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.