Change in osmo-trx[master]: uhd: No need to use dynamic mem for rx_buffers

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue Apr 30 21:50:14 UTC 2019


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/13833


Change subject: uhd: No need to use dynamic mem for rx_buffers
......................................................................

uhd: No need to use dynamic mem for rx_buffers

This way we don't need to free explicitly and we simplify code.

Change-Id: I39b293c24053298256626fa78344102032fc2104
---
M Transceiver52M/device/uhd/UHDDevice.cpp
M Transceiver52M/device/uhd/UHDDevice.h
2 files changed, 12 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/33/13833/1

diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp
index 79e5855..3e53111 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -173,9 +173,6 @@
 uhd_device::~uhd_device()
 {
 	stop();
-
-	for (size_t i = 0; i < rx_buffers.size(); i++)
-		delete rx_buffers[i];
 }
 
 void uhd_device::init_gains()
@@ -459,7 +456,6 @@
 	rx_freqs.resize(chans);
 	tx_gains.resize(chans);
 	rx_gains.resize(chans);
-	rx_buffers.resize(chans);
 
 	switch (ref) {
 	case REF_INTERNAL:
@@ -513,8 +509,7 @@
 
 	// Create receive buffer
 	size_t buf_len = SAMPLE_BUF_SZ / sizeof(uint32_t);
-	for (size_t i = 0; i < rx_buffers.size(); i++)
-		rx_buffers[i] = new smpl_buf(buf_len, rx_rate);
+	rx_buffers = std::vector<smpl_buf>(chans, smpl_buf(buf_len, rx_rate));
 
 	// Create vector buffer
 	pkt_bufs = std::vector<std::vector<short> >(chans, std::vector<short>(2 * rx_spp));
@@ -711,15 +706,15 @@
 	LOGC(DDEV, DEBUG) << "Requested timestamp = " << ts.get_real_secs();
 
 	// Check that timestamp is valid
-	rc = rx_buffers[0]->avail_smpls(timestamp);
+	rc = rx_buffers[0].avail_smpls(timestamp);
 	if (rc < 0) {
-		LOGC(DDEV, ERROR) << rx_buffers[0]->str_code(rc);
-		LOGC(DDEV, ERROR) << rx_buffers[0]->str_status(timestamp);
+		LOGC(DDEV, ERROR) << rx_buffers[0].str_code(rc);
+		LOGC(DDEV, ERROR) << rx_buffers[0].str_status(timestamp);
 		return 0;
 	}
 
 	// Receive samples from the usrp until we have enough
-	while (rx_buffers[0]->avail_smpls(timestamp) < len) {
+	while (rx_buffers[0].avail_smpls(timestamp) < len) {
 		thread_enable_cancel(false);
 		size_t num_smpls = rx_stream->recv(pkt_ptrs, rx_spp,
 						   metadata, 0.1, true);
@@ -745,14 +740,14 @@
 		LOGC(DDEV, DEBUG) << "Received timestamp = " << ts.get_real_secs();
 
 		for (size_t i = 0; i < rx_buffers.size(); i++) {
-			rc = rx_buffers[i]->write((short *) &pkt_bufs[i].front(),
+			rc = rx_buffers[i].write((short *) &pkt_bufs[i].front(),
 						  num_smpls,
 						  metadata.time_spec.to_ticks(rx_rate));
 
 			// Continue on local overrun, exit on other errors
 			if ((rc < 0)) {
-				LOGC(DDEV, ERROR) << rx_buffers[i]->str_code(rc);
-				LOGC(DDEV, ERROR) << rx_buffers[i]->str_status(timestamp);
+				LOGC(DDEV, ERROR) << rx_buffers[i].str_code(rc);
+				LOGC(DDEV, ERROR) << rx_buffers[i].str_status(timestamp);
 				if (rc != smpl_buf::ERROR_OVERFLOW)
 					return 0;
 			}
@@ -761,10 +756,10 @@
 
 	// We have enough samples
 	for (size_t i = 0; i < rx_buffers.size(); i++) {
-		rc = rx_buffers[i]->read(bufs[i], len, timestamp);
+		rc = rx_buffers[i].read(bufs[i], len, timestamp);
 		if ((rc < 0) || (rc != len)) {
-			LOGC(DDEV, ERROR) << rx_buffers[i]->str_code(rc);
-			LOGC(DDEV, ERROR) << rx_buffers[i]->str_status(timestamp);
+			LOGC(DDEV, ERROR) << rx_buffers[i].str_code(rc);
+			LOGC(DDEV, ERROR) << rx_buffers[i].str_status(timestamp);
 			return 0;
 		}
 	}
diff --git a/Transceiver52M/device/uhd/UHDDevice.h b/Transceiver52M/device/uhd/UHDDevice.h
index 2a9fc02..5d7e4bd 100644
--- a/Transceiver52M/device/uhd/UHDDevice.h
+++ b/Transceiver52M/device/uhd/UHDDevice.h
@@ -139,7 +139,7 @@
 	uhd::time_spec_t prev_ts;
 
 	TIMESTAMP ts_initial, ts_offset;
-	std::vector<smpl_buf *> rx_buffers;
+	std::vector<smpl_buf> rx_buffers;
 	/* Sample buffers used to receive samples from UHD: */
 	std::vector<std::vector<short> > pkt_bufs;
 	/* Used to call UHD API: Buffer pointer of each elem in pkt_ptrs will

-- 
To view, visit https://gerrit.osmocom.org/13833
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I39b293c24053298256626fa78344102032fc2104
Gerrit-Change-Number: 13833
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190430/c12857d9/attachment.htm>


More information about the gerrit-log mailing list