diff --git a/include/mbgl/util/threadpool.hpp b/include/mbgl/util/threadpool.hpp deleted file mode 100644 index ff913ec50..000000000 --- a/include/mbgl/util/threadpool.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MBGL_UTIL_THREADPOOL -#define MBGL_UTIL_THREADPOOL - -#include -#include -#include -#include - -namespace mbgl { -namespace util { - -class Threadpool { -private: - class Worker { - public: - Worker(Threadpool& pool); - ~Worker(); - static void *loop(void *ptr); - - private: - Threadpool& pool; - pthread_t thread; - }; - -public: - Threadpool(int max_workers = 4); - typedef void (*Callback)(void *); - void add(Callback callback, void *data); - -private: - typedef std::pair Task; - const int max_workers; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t condition = PTHREAD_COND_INITIALIZER; - std::forward_list workers; - int worker_count = 0; - std::queue tasks; -}; - -extern std::unique_ptr threadpool; - -} -} - -#endif - diff --git a/src/util/threadpool.cpp b/src/util/threadpool.cpp deleted file mode 100644 index f19032ee0..000000000 --- a/src/util/threadpool.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -using namespace mbgl::util; - -std::unique_ptr mbgl::util::threadpool = std::make_unique(std::thread::hardware_concurrency()); - -Threadpool::Threadpool(int max_workers) - : max_workers(max_workers) { -} - -void Threadpool::add(Callback callback, void *data) { - if (worker_count < max_workers) { - worker_count++; - workers.emplace_front(*this); - } - - pthread_mutex_lock(&mutex); - tasks.push(std::make_pair(callback, data)); - pthread_mutex_unlock(&mutex); - pthread_cond_signal(&condition); -} - -Threadpool::Worker::Worker(Threadpool& pool) - : pool(pool) { - pthread_create(&thread, nullptr, loop, (void *)this); -} - -Threadpool::Worker::~Worker() { - pthread_cancel(thread); -} - - -void *Threadpool::Worker::loop(void *ptr) { - Worker *worker = static_cast(ptr); - Threadpool& pool = worker->pool; - - pthread_mutex_lock(&pool.mutex); - while (true) { - if (pool.tasks.size()) { - Threadpool::Task task = pool.tasks.front(); - pool.tasks.pop(); - pthread_mutex_unlock(&pool.mutex); - task.first(task.second); - pthread_mutex_lock(&pool.mutex); - } else { - pthread_cond_wait(&pool.condition, &pool.mutex); - } - } - - return nullptr; -}