Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Queue.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_QUEUE_H
10 #define TALVOS_QUEUE_H
11 
12 #include <condition_variable>
13 #include <mutex>
14 #include <queue>
15 #include <set>
16 #include <thread>
17 
18 namespace talvos
19 {
20 
21 class Command;
22 class Device;
23 
25 class Queue
26 {
27 public:
29  Queue(Device &Dev);
30 
32  ~Queue();
33 
34  // Do not allow Queue objects to be copied.
36  Queue(const Queue &) = delete;
37  Queue &operator=(const Queue &) = delete;
39 
43  void submit(const std::vector<Command *> &NewCommands,
44  volatile bool *Fence = nullptr);
45 
47  void waitIdle();
48 
49 private:
52 
54  std::queue<Command *> Commands;
55 
57  std::set<volatile bool *> Fences;
58 
59  // Background queue thread used to progress command execution.
60  std::thread Thread;
61 
63  std::mutex Mutex;
64 
66  std::condition_variable StateChanged;
67 
69  volatile bool Running;
70 
72  void run();
73 };
74 
75 } // namespace talvos
76 
77 #endif
void submit(const std::vector< Command * > &NewCommands, volatile bool *Fence=nullptr)
Submit a batch of commands to the queue.
Definition: Queue.cpp:37
std::condition_variable StateChanged
Condition variable to signal when queue state has changed.
Definition: Queue.h:66
Device & Dev
The device that this queue will execute work on.
Definition: Queue.h:51
std::queue< Command * > Commands
The queue of pending commands.
Definition: Queue.h:54
volatile bool Running
Flag to signal whether the queue thread is active.
Definition: Queue.h:69
~Queue()
Destroy the queue.
Definition: Queue.cpp:24
std::thread Thread
Definition: Queue.h:60
This class represents a queue for executing commands on a device.
Definition: Queue.h:25
void run()
Entry point for background queue thread.
Definition: Queue.cpp:58
void waitIdle()
Wait until all commands in the queue have completed.
Definition: Queue.cpp:104
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
std::set< volatile bool * > Fences
A set of pending fences.
Definition: Queue.h:57
Queue & operator=(const Queue &)=delete
std::mutex Mutex
Mutex used to guard queue updates.
Definition: Queue.h:63
Queue(Device &Dev)
Create a queue for the specified device.
Definition: Queue.cpp:18