-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worker.h
53 lines (50 loc) · 1.3 KB
/
Worker.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
50
51
52
53
#ifndef WORKER_H
// imports
#include <thread> // for threading
#pragma once // make sure source file gets only included once
/*!class that implements the Worker*/
class Worker
{
public:
/**
* constructor of Worker. Default - does nothing
*/
Worker() = default;
/**
* inits and starts the thread
*/
void start();
/**
* stops the thread, deconstructs it
*/
void stop();
/**
* joining function. joins the thread, stops it afterwards
*/
void join();
private:
std::thread m_thread; // thread object
bool m_terminate = false; // init bool whether thread is terminated to false
bool m_running = false; // init bool whether thread is running to false
/**
* working function
*/
void work();
/**
* checks whether thread is running
* @return m_running: whether thread is running or not [Boolean]
*/
bool isRunning() const;
/**
* checks whether thread is already terminated
* @return m_terminate: whether thread is terminated or not [Boolean]
*/
bool isTerminated() const;
protected:
/**
* 'worker' function that does the actual work
* @return true: when finished, returns true to stop the worker [Boolean]
*/
virtual bool step() { return false; };
};
#endif // !WORKER_H