aboutsummaryrefslogtreecommitdiffstats
path: root/src/ModPlugin.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-03-06 22:53:36 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-03-06 22:53:36 +0100
commit56dfbcd73529ee6dc42a17a139c9ceaccf1def3d (patch)
tree47580fcfa894fca04805f670ec6acf30a08a6f5d /src/ModPlugin.cpp
parent5bea9241b246cfc4b9abef3d265a96d52a377c37 (diff)
downloaddabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.gz
dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.bz2
dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.zip
Avoid copies in ThreadsafeQueue and Buffer
Diffstat (limited to 'src/ModPlugin.cpp')
-rw-r--r--src/ModPlugin.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/ModPlugin.cpp b/src/ModPlugin.cpp
index d567a90..f907ba8 100644
--- a/src/ModPlugin.cpp
+++ b/src/ModPlugin.cpp
@@ -2,7 +2,7 @@
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Her Majesty the
Queen in Right of Canada (Communications Research Center Canada)
- Copyright (C) 2017
+ Copyright (C) 2018
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -29,6 +29,7 @@
#include "Utils.h"
#include <stdexcept>
#include <string>
+#include <cstring>
#define MODASSERT(cond) \
if (not (cond)) { \
@@ -92,16 +93,14 @@ int PipelinedModCodec::process(Buffer* dataIn, Buffer* dataOut)
return 0;
}
- std::shared_ptr<Buffer> inbuffer =
- std::make_shared<Buffer>(dataIn->getLength(), dataIn->getData());
-
- m_input_queue.push(inbuffer);
+ Buffer inbuffer;
+ std::swap(inbuffer, *dataIn);
+ m_input_queue.push(std::move(inbuffer));
if (m_ready_to_output_data) {
- std::shared_ptr<Buffer> outbuffer;
+ Buffer outbuffer;
m_output_queue.wait_and_pop(outbuffer);
-
- dataOut->setData(outbuffer->getData(), outbuffer->getLength());
+ std::swap(outbuffer, *dataOut);
}
else {
dataOut->setLength(dataIn->getLength());
@@ -132,21 +131,21 @@ void PipelinedModCodec::process_thread()
set_realtime_prio(1);
while (m_running) {
- std::shared_ptr<Buffer> dataIn;
+ Buffer dataIn;
m_input_queue.wait_and_pop(dataIn);
- if (!dataIn or dataIn->getLength() == 0) {
+ if (dataIn.getLength() == 0) {
break;
}
- std::shared_ptr<Buffer> dataOut = std::make_shared<Buffer>();
- dataOut->setLength(dataIn->getLength());
+ Buffer dataOut;
+ dataOut.setLength(dataIn.getLength());
- if (internal_process(dataIn.get(), dataOut.get()) == 0) {
+ if (internal_process(&dataIn, &dataOut) == 0) {
m_running = false;
}
- m_output_queue.push(dataOut);
+ m_output_queue.push(std::move(dataOut));
}
m_running = false;