remove thread naming

This commit is contained in:
Konstantin Käfer
2014-03-03 13:01:09 +01:00
parent f850856cec
commit f1f146b01e
2 changed files with 5 additions and 9 deletions

View File

@@ -4,8 +4,6 @@
#include <pthread.h>
#include <forward_list>
#include <queue>
#include <string>
#include "std.hpp"
namespace llmr {
namespace util {
@@ -14,13 +12,12 @@ class Threadpool {
private:
class Worker {
public:
Worker(Threadpool& pool, const std::string name);
Worker(Threadpool& pool);
~Worker();
static void *loop(void *ptr);
private:
Threadpool& pool;
const std::string name;
pthread_t thread;
};

View File

@@ -1,4 +1,5 @@
#include <llmr/util/threadpool.hpp>
#include <llmr/util/std.hpp>
#include <thread>
using namespace llmr::util;
@@ -12,7 +13,7 @@ Threadpool::Threadpool(int max_workers)
void Threadpool::add(Callback callback, void *data) {
if (worker_count < max_workers) {
worker_count++;
workers.emplace_front(*this, std::string("worker ") + std::to_string(worker_count));
workers.emplace_front(*this);
}
pthread_mutex_lock(&mutex);
@@ -21,9 +22,8 @@ void Threadpool::add(Callback callback, void *data) {
pthread_cond_signal(&condition);
}
Threadpool::Worker::Worker(Threadpool& pool, const std::string name)
: pool(pool),
name(name) {
Threadpool::Worker::Worker(Threadpool& pool)
: pool(pool) {
pthread_create(&thread, nullptr, loop, (void *)this);
}
@@ -36,7 +36,6 @@ void *Threadpool::Worker::loop(void *ptr) {
Worker *worker = static_cast<Worker *>(ptr);
Threadpool& pool = worker->pool;
pthread_setname_np(worker->name.c_str());
pthread_mutex_lock(&pool.mutex);
while (true) {
if (pool.tasks.size()) {