blob: 99dcd65607033aa25f26fc5c7a205edcbfec84fa [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WORKER_POOL_H_
#define WORKER_POOL_H_
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>
#include "base/logging.h"
#include "base/macros.h"
#include "task.h"
class WorkerPool {
public:
WorkerPool();
WorkerPool(size_t thread_count);
~WorkerPool();
void PostTask(Task work);
private:
void Worker();
std::vector<std::thread> threads_;
std::queue<base::OnceClosure> task_queue_;
std::mutex queue_mutex_;
std::condition_variable_any pool_notifier_;
bool should_stop_processing_;
DISALLOW_COPY_AND_ASSIGN(WorkerPool);
};
#endif // WORKER_POOL_H_