-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasker.h
More file actions
55 lines (42 loc) · 927 Bytes
/
tasker.h
File metadata and controls
55 lines (42 loc) · 927 Bytes
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
50
51
52
53
54
55
#pragma once
#include <iostream>
#include <vector>
#include <thread>
#include <list>
#include <mutex>
#include <atomic>
using std::vector;
using std::list;
using std::cout;
using std::endl;
using std::thread;
using std::unique_lock;
using std::mutex;
using std::bind;
using std::condition_variable;
using std::atomic_bool;
class Tasker
{
public:
typedef std::function<void()> task_;
//Secure constructor
static Tasker* create(int);
//Constructor
Tasker(int);
//Destructor
~Tasker();
//Add new tasks to task list
void add_task(task_);
//have calling thread wait until tasks are completed
void wait();
private:
//get task, run task, remove task from list
void Tasker::Run();
vector<thread*> thread_vector;
condition_variable run_cv;
condition_variable end_cv;
list<task_> task_list;
atomic_bool exit;
atomic_bool end_condition;
mutex mx;
};