-
Notifications
You must be signed in to change notification settings - Fork 3
/
task-queue.cpp
60 lines (46 loc) · 978 Bytes
/
task-queue.cpp
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
#include "task-queue.h"
namespace GPGPU_LIB
{
struct GPGPUTaskQueue;
GPGPUTask::GPGPUTask() :
kernelCode(""),
kernelName(""),
parameterName(""),
parameterPosition(0),
offset(0),
globalSize(0),
localSize(0),
hostParPtr(nullptr),
comQuePtr(nullptr),
taskType(0),
conPtr(nullptr),
mutexPtr(nullptr),
sharedTaskQueue(nullptr),
globalOffset(0)
{}
GPGPUTaskQueue::GPGPUTaskQueue()
{
}
bool GPGPUTaskQueue::inProgress()
{
std::lock_guard<std::mutex> lock(syncPoint);
return tasks.size() > 0;
}
void GPGPUTaskQueue::push(GPGPUTask task)
{
std::lock_guard<std::mutex> lock(syncPoint);
tasks.push(task);
condition.notify_all();
}
GPGPUTask GPGPUTaskQueue::pop()
{
std::unique_lock<std::mutex> lock(syncPoint);
while (tasks.size() == 0)
{
condition.wait(lock, [&]() { return tasks.size() > 0; });
}
GPGPUTask result = tasks.front();
tasks.pop();
return result;
}
}