-
Notifications
You must be signed in to change notification settings - Fork 0
/
threading.cc
54 lines (44 loc) · 1.27 KB
/
threading.cc
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
#include "threading.h"
void ByteStreamWriter::writeBytes(const ByteStream::series_t &series) {
stream->writeBytes(series);
}
void ByteStreamWriter::writeByte(uint8_t byte) {
stream->writeByte(byte);
}
void ByteStreamWriter::flushOutput() {
stream->flushOutput();
}
std::list<LockedValue<ByteStreamWriter>> &LockedMultiWriter::locks() {
return _locks;
}
void LockedMultiWriter::writeBytes(ByteStream::series_t bytes) {
for (auto &lock : _locks) {
lock->writeBytes(bytes);
}
}
void LockedMultiWriter::writeByte(uint8_t byte) {
for (auto &lock : _locks) {
lock->writeByte(byte);
}
}
void LockedMultiWriter::flushOutput() {
for (auto &lock : _locks) {
lock->flushOutput();
}
}
void MultiWriter::addStream(const std::shared_ptr<MutexValue<ByteStreamWriter>> &stream) {
auto list_lock = streams.lock();
list_lock->remove(stream);
list_lock->push_back(stream);
}
void MultiWriter::removeStream(const std::shared_ptr<MutexValue<ByteStreamWriter>> &stream) {
streams.lock()->remove(stream);
}
LockedMultiWriter MultiWriter::lock() {
auto _lock = LockedMultiWriter();
auto list_lock = streams.lock();
for (auto &stream : list_lock.get()) {
_lock.locks().emplace_back(*stream);
}
return _lock;
}