Allow to get the size of the queue.
This commit is contained in:
@@ -31,7 +31,6 @@ int main(int argc, char* argv[]) {
|
|||||||
if (auto file_body = r->file_body()) {
|
if (auto file_body = r->file_body()) {
|
||||||
file_body->Move(path);
|
file_body->Move(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -54,9 +54,14 @@ public:
|
|||||||
not_empty_cv_.notify_one();
|
not_empty_cv_.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t Size() const {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
return message_list_.size();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<T> message_list_;
|
std::list<T> message_list_;
|
||||||
std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
std::condition_variable not_empty_cv_;
|
std::condition_variable not_empty_cv_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -250,10 +250,13 @@ void Server::WorkerRoutine() {
|
|||||||
void Server::StopWorkers() {
|
void Server::StopWorkers() {
|
||||||
LOG_INFO("Stopping workers...");
|
LOG_INFO("Stopping workers...");
|
||||||
|
|
||||||
// Clear pending connections.
|
// Clear/drop pending connections.
|
||||||
// The connections will be closed later.
|
// The connections will be closed later (see DoStop).
|
||||||
LOG_INFO("Clear pending connections...");
|
// Alternatively, we can wait for the pending connections to be handled.
|
||||||
queue_.Clear();
|
if (queue_.Size() != 0) {
|
||||||
|
LOG_INFO("Clear pending connections...");
|
||||||
|
queue_.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
// Enqueue a null connection to trigger the first worker to stop.
|
// Enqueue a null connection to trigger the first worker to stop.
|
||||||
queue_.Push(ConnectionPtr());
|
queue_.Push(ConnectionPtr());
|
||||||
|
|||||||
Reference in New Issue
Block a user