Skip to content

Commit b029bf1

Browse files
author
KolKir
committed
Remove thread class, changed with std one
1 parent 8994ed5 commit b029bf1

4 files changed

Lines changed: 15 additions & 108 deletions

File tree

‎include/cpptask/taskthread.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,41 @@
2828
#ifndef _TASKTHREAD_H_
2929
#define _TASKTHREAD_H_
3030

31-
#include "thread.h"
3231
#include "event.h"
3332
#include "taskmanager.h"
3433

3534
#include <memory>
3635
#include <atomic>
36+
#include <thread>
3737

3838
namespace cpptask
3939
{
4040

4141
class Task;
4242
class TaskThreadPool;
43-
class TaskThread: public Thread
43+
class TaskThread
4444
{
4545
public:
4646
TaskThread(TaskThreadPool& threadPool, Semaphore& newTaskEvent);
4747
~TaskThread();
4848

49-
virtual void Run();
50-
5149
void Stop();
5250

5351
TaskManager& GetTaskManager();
5452

5553
TaskThread(const TaskThread&) = delete;
5654
TaskThread& operator=(const TaskThread&) = delete;
55+
56+
private:
57+
58+
void Run();
59+
5760
private:
5861
Event stopEvent;
5962
Semaphore& newTaskEvent;
6063
std::unique_ptr<TaskManager> manager;
6164
std::atomic<bool> done;
65+
std::thread thread;
6266
};
6367

6468
}

‎include/cpptask/taskthreadimpl.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ namespace cpptask
3838

3939
inline TaskThread::TaskThread(TaskThreadPool& threadPool, Semaphore& newTaskEvent)
4040
: newTaskEvent(newTaskEvent)
41+
, manager(new TaskManager(threadPool, newTaskEvent, this))
42+
, done(false)
43+
, thread(std::bind(&TaskThread::Run, this))
4144
{
42-
manager.reset(new TaskManager(threadPool, newTaskEvent, this));
43-
done.store(false, std::memory_order_relaxed);
4445
}
4546

4647
inline TaskThread::~TaskThread()
4748
{
4849
Stop();
49-
Join();
50+
if (thread.joinable())
51+
{
52+
thread.join();
53+
}
5054
}
5155

5256
inline void TaskThread::Run()

‎include/cpptask/thread.h‎

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎include/cpptask/threadpool.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ class TaskThreadPool
5151
TaskThreadPtr tptr(new TaskThread(*this, newTaskEvent));
5252
threads.push_back(tptr);
5353
}
54-
55-
for (size_t i = 0; i < threadsNum; ++i)
56-
{
57-
threads[i]->Start();
58-
}
5954
}
6055

6156
~TaskThreadPool()
@@ -65,7 +60,6 @@ class TaskThreadPool
6560
for (;i != e; ++i)
6661
{
6762
(*i)->Stop();
68-
(*i)->Join();
6963
}
7064
}
7165

0 commit comments

Comments
 (0)