-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicThread.h
49 lines (41 loc) · 1.06 KB
/
BasicThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// BasicThread.h
// ThreadPool
//
// Created by Andrew Rose on 22.07.13.
// Copyright (c) 2013 Andrew Rose. All rights reserved.
//
#ifndef __ThreadPool__BasicThread__
#define __ThreadPool__BasicThread__
#include <iostream>
#include <thread>
#include <queue>
#include <condition_variable>
template<typename I>
class IBasicThreads
{
private:
std::thread workThread;
std::condition_variable newSignalCondition;
I& workFunctor;
public:
IBasicThreads(I& func);
void ReciveSignal(const typename I::value_type& signal);
~IBasicThreads();
};
template<typename I>
IBasicThreads<I>::IBasicThreads(I& func):workFunctor(func),workThread(I::DoJob,&func)
{
}
template<typename I>
IBasicThreads<I>::~IBasicThreads()
{
workFunctor.TerminateThread();
workThread.join();
}
template<typename I>
void IBasicThreads<I>::ReciveSignal(const typename I::value_type& signal)
{
workFunctor.ReciveSignal(signal);
}
#endif /* defined(__ThreadPool__BasicThread__) */