-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorker.cpp
More file actions
46 lines (37 loc) · 869 Bytes
/
Worker.cpp
File metadata and controls
46 lines (37 loc) · 869 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
#include "Worker.h"
#include "JobQueue.h"
#include "IJob.h"
#include "ThreadManager.h"
worker::worker(uint16_t i_id, job_queue* i_job_queue, int CPU, std::string team) : id_(i_id),
job_queue_(i_job_queue),is_working_(true)
{
thread_ = std::thread(&worker::do_job, this, job_queue_);
if (team != "GameTeam")
{
const DWORD_PTR a = thread_manager::TheThread.set_processor(CPU);
DWORD_PTR dw = SetThreadAffinityMask(thread_.native_handle(), a);
}
}
worker::~worker()
{
thread_.join();
}
void worker::do_job(job_queue* i_job_queue)
{
// validate inputs
bool stop_working = false;
do
{
i_job* job = i_job_queue->get_job();
if (job)
{
job->do_work();
delete job;
stop_working = i_job_queue->has_shutdown_been_requested();
}
else
{
stop_working = i_job_queue->has_shutdown_been_requested();
}
} while (stop_working == false);
}