summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/NetworkLookup.cpp
blob: 5cd7ecfc473190c26e0a1e36d840c51ecb5c97a5 (plain) (blame)
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
60
61
62
63

// NetworkLookup.cpp

// Implements the cNetworkLookup class representing an executor for asynchronous lookup tasks


#include "Globals.h"
#include "NetworkLookup.h"




cNetworkLookup::cNetworkLookup() :
	cIsThread("NetworkLookup")
{
}





cNetworkLookup::~cNetworkLookup()
{
	Stop();
}





void cNetworkLookup::ScheduleLookup(std::function<void()> a_Lookup)
{
	m_WorkQueue.EnqueueItem(std::move(a_Lookup));
}





void cNetworkLookup::Stop()
{
	m_ShouldTerminate = true;
	m_WorkQueue.Clear();
	m_WorkQueue.EnqueueItem([](){});  // Dummy work to wake up the thread
	cIsThread::Stop();
}





void cNetworkLookup::Execute()
{
	while (!m_ShouldTerminate)
	{
		// Execute the next task in the queue
		auto Work = m_WorkQueue.DequeueItem();
		Work();
	}
}