TaskQueue method to internal size adjust (#442)

I use a custom TaskQueue, with variable number of workers, adding workers on demand is an easy task when new connection arrive (in enqueue function) however i need another funtion to be called even (or better) went no new connections arrives to reduce workers count. I only added a new virtual method in TaskQueue class to allow custom class to adjust workers size over time. Even if this methods is called frequenlty custom class can keep a "last_update" counter to check if need to adjust worker count or any other internal task. Without this function i need an external thread to make this adjust task.
This commit is contained in:
evg82 2020-04-25 23:55:20 +02:00 committed by GitHub
parent a5005789ff
commit 5928e0af1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -368,6 +368,7 @@ public:
TaskQueue() = default;
virtual ~TaskQueue() = default;
virtual void enqueue(std::function<void()> fn) = 0;
virtual void queue_adjust() { };
virtual void shutdown() = 0;
};
@ -3497,6 +3498,7 @@ inline bool Server::listen_internal() {
auto val = detail::select_read(svr_sock_, 0, 100000);
if (val == 0) { // Timeout
task_queue->queue_adjust();
continue;
}