summaryrefslogtreecommitdiff
path: root/include/llmr/util/threadpool.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-03-03 12:55:32 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-03-03 12:55:32 +0100
commitf850856cecf3358f5cf63a8cfae00a1bd65a6d8e (patch)
tree526aed06ca82ccfe72677c64e0e7c235b0de153e /include/llmr/util/threadpool.hpp
parentc076da0ae2f2e8c8221b727d9197ae5257c703f9 (diff)
downloadqtlocation-mapboxgl-f850856cecf3358f5cf63a8cfae00a1bd65a6d8e.tar.gz
move requests to global threadpool
Diffstat (limited to 'include/llmr/util/threadpool.hpp')
-rw-r--r--include/llmr/util/threadpool.hpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/llmr/util/threadpool.hpp b/include/llmr/util/threadpool.hpp
index f47bd5bf8f..817cdc6515 100644
--- a/include/llmr/util/threadpool.hpp
+++ b/include/llmr/util/threadpool.hpp
@@ -4,30 +4,33 @@
#include <pthread.h>
#include <forward_list>
#include <queue>
+#include <string>
+#include "std.hpp"
namespace llmr {
namespace util {
class Threadpool {
+private:
class Worker {
public:
- Worker(Threadpool& pool);
+ Worker(Threadpool& pool, const std::string name);
~Worker();
static void *loop(void *ptr);
private:
Threadpool& pool;
+ const std::string name;
pthread_t thread;
};
public:
- typedef void (*Callback)(void *);
- typedef std::pair<Callback, void *> Task;
Threadpool(int max_workers = 4);
-
+ typedef void (*Callback)(void *);
void add(Callback callback, void *data);
private:
+ typedef std::pair<Callback, void *> Task;
const int max_workers;
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
pthread_cond_t condition = PTHREAD_COND_INITIALIZER;
@@ -36,6 +39,8 @@ private:
std::queue<Task> tasks;
};
+extern std::unique_ptr<Threadpool> threadpool;
+
}
}