diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-03-06 22:53:36 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-03-06 22:53:36 +0100 |
commit | 56dfbcd73529ee6dc42a17a139c9ceaccf1def3d (patch) | |
tree | 47580fcfa894fca04805f670ec6acf30a08a6f5d /src/InputZeroMQReader.cpp | |
parent | 5bea9241b246cfc4b9abef3d265a96d52a377c37 (diff) | |
download | dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.gz dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.bz2 dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.zip |
Avoid copies in ThreadsafeQueue and Buffer
Diffstat (limited to 'src/InputZeroMQReader.cpp')
-rw-r--r-- | src/InputZeroMQReader.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/InputZeroMQReader.cpp b/src/InputZeroMQReader.cpp index 1bb325f..e1e1c6d 100644 --- a/src/InputZeroMQReader.cpp +++ b/src/InputZeroMQReader.cpp @@ -36,7 +36,6 @@ #include <cstdio> #include <stdint.h> #include "zmq.hpp" -#include <boost/thread/thread.hpp> #include "InputReader.h" #include "PcDebug.h" #include "Utils.h" @@ -88,7 +87,7 @@ int InputZeroMQReader::Open(const string& uri, size_t max_queued_frames) m_max_queued_frames = max_queued_frames; - m_recv_thread = boost::thread(&InputZeroMQReader::RecvProcess, this); + m_recv_thread = std::thread(&InputZeroMQReader::RecvProcess, this); return 0; } @@ -99,7 +98,7 @@ int InputZeroMQReader::GetNextFrame(void* buffer) return 0; } - shared_ptr<vector<uint8_t> > incoming; + vector<uint8_t> incoming; /* Do some prebuffering because reads will happen in bursts * (4 ETI frames in TM1) and we should make sure that @@ -122,11 +121,11 @@ int InputZeroMQReader::GetNextFrame(void* buffer) const size_t framesize = 6144; - if (incoming->empty()) { + if (incoming.empty()) { return 0; } - else if (incoming->size() == framesize) { - memcpy(buffer, &incoming->front(), framesize); + else if (incoming.size() == framesize) { + memcpy(buffer, &incoming.front(), framesize); } else { throw logic_error("ZMQ ETI not 6144"); @@ -184,7 +183,7 @@ void InputZeroMQReader::RecvProcess() const int num_events = zmq::poll(items, 1, zmq_timeout_ms); if (num_events == 0) { // timeout is signalled by an empty buffer - auto buf = make_shared<vector<uint8_t> >(); + vector<uint8_t> buf; m_in_messages.push(buf); continue; } @@ -228,7 +227,7 @@ void InputZeroMQReader::RecvProcess() throw runtime_error(ss.str()); } else { - auto buf = make_shared<vector<uint8_t> >(6144, 0x55); + vector<uint8_t> buf(6144, 0x55); const int framesize = dab_msg->buflen[i]; @@ -236,13 +235,13 @@ void InputZeroMQReader::RecvProcess() throw runtime_error("ZeroMQ packet too small"); } - memcpy(&buf->front(), + memcpy(&buf.front(), ((uint8_t*)incoming.data()) + offset, framesize); offset += framesize; - queue_size = m_in_messages.push(buf); + queue_size = m_in_messages.push(move(buf)); etiLog.log(trace, "ZMQ,push %zu", queue_size); } } |