-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.cpp
More file actions
43 lines (28 loc) · 862 Bytes
/
module.cpp
File metadata and controls
43 lines (28 loc) · 862 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
#include <iostream>
#include "module.h"
Module::Module(std::shared_ptr<Queue<std::unique_ptr<Command>>> &queue): Module() {
output = queue;
} // Module::Module
Module::Module() {
input = std::make_shared<Queue<std::unique_ptr<Command>>>();
} // Module::Module
Module::~Module() {
worker.join();
} // Module::Module
std::shared_ptr<Queue<std::unique_ptr<Command>>> Module::get_queue() {
return input;
} // Module::get_queue
int Module::get_type() {
return type;
} // Module::get_type
void Module::start() {
worker = std::thread(&Module::main_loop, this);
} // Module::start
void Module::main_loop() {
while (true) {
std::unique_ptr<Command> cmd = input.get()->dequeue();
if (cmd.get()->dst == type and cmd.get()->command == TERM)
return;
run(std::move(cmd));
}
} // Module::start