summaryrefslogtreecommitdiff
path: root/src/threadengine.cpp
blob: c2aa3da20ae7e34d287ec0afd774d8bc83ad8321 (plain)
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
56
57
58
59
#include "services.h"

ThreadEngine threadEngine;

/** Check for finished threads
 */
void ThreadEngine::Process()
{
	for (unsigned i = this->threads.size(); i > 0; --i)
	{
		Thread *t = this->threads[i - 1];

		if (t->GetExitState())
		{
			t->Join();
			delete t;
		}
	}
}

/** Threads constructor
 */
Thread::Thread() : exit(false)
{
	threadEngine.threads.push_back(this);
}

/** Threads destructor
 */
Thread::~Thread()
{
	std::vector<Thread *>::iterator it = std::find(threadEngine.threads.begin(), threadEngine.threads.end(), this);

	if (it != threadEngine.threads.end())
	{
		threadEngine.threads.erase(it);
	}
}

/** Sets the exit state as true informing the thread we want it to shut down
 */
void Thread::SetExitState()
{
	exit = true;
}

/** Returns the exit state of the thread
 * @return true if we want to exit
 */
bool Thread::GetExitState() const
{
	return exit;
}

/** Called to run the thread, should be overloaded
 */
void Thread::Run()
{
}