Change in ...osmo-trx[master]: Transceiver: Clean up code passing parameters to threads

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/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Jul 23 09:06:02 UTC 2019


pespin has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmo-trx/+/14898 )

Change subject: Transceiver: Clean up code passing parameters to threads
......................................................................

Transceiver: Clean up code passing parameters to threads

TransceiverChannel naming was misleading there. It's simply a data type
used to pass 2 parameters through the void* of the thread entry
function, so let's clearly specify is a storage for thread params.
Furthermore, we don't need a full C++ class for that, let's simply use a
struct.

Change-Id: I6e3898a8a66520cc5b2a7df9b9ae01b0b272387f
---
M Transceiver52M/Transceiver.cpp
M Transceiver52M/Transceiver.h
2 files changed, 37 insertions(+), 45 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index a47f7db..b12a498 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -240,10 +240,12 @@
 
   /* Start control threads */
   for (size_t i = 0; i < mChans; i++) {
-    TransceiverChannel *chan = new TransceiverChannel(this, i);
+    TrxChanThParams *params = (TrxChanThParams *)malloc(sizeof(struct TrxChanThParams));
+    params->trx = this;
+    params->num = i;
     mControlServiceLoopThreads[i] = new Thread(stackSize);
     mControlServiceLoopThreads[i]->start((void * (*)(void*))
-                                 ControlServiceLoopAdapter, (void*) chan);
+                                 ControlServiceLoopAdapter, (void*) params);
 
     if (i && filler == FILLER_DUMMY)
       filler = FILLER_ZERO;
@@ -292,15 +294,19 @@
 
   /* Launch uplink and downlink burst processing threads */
   for (size_t i = 0; i < mChans; i++) {
-    TransceiverChannel *chan = new TransceiverChannel(this, i);
+    TrxChanThParams *params = (TrxChanThParams *)malloc(sizeof(struct TrxChanThParams));
+    params->trx = this;
+    params->num = i;
     mRxServiceLoopThreads[i] = new Thread(stackSize);
     mRxServiceLoopThreads[i]->start((void * (*)(void*))
-                            RxUpperLoopAdapter, (void*) chan);
+                            RxUpperLoopAdapter, (void*) params);
 
-    chan = new TransceiverChannel(this, i);
+    params = (TrxChanThParams *)malloc(sizeof(struct TrxChanThParams));
+    params->trx = this;
+    params->num = i;
     mTxPriorityQueueServiceLoopThreads[i] = new Thread(stackSize);
     mTxPriorityQueueServiceLoopThreads[i]->start((void * (*)(void*))
-                            TxUpperLoopAdapter, (void*) chan);
+                            TxUpperLoopAdapter, (void*) params);
   }
 
   mForceClockInterface = true;
@@ -1108,13 +1114,13 @@
 
 }
 
-void *RxUpperLoopAdapter(TransceiverChannel *chan)
+void *RxUpperLoopAdapter(TrxChanThParams *params)
 {
   char thread_name[16];
-  Transceiver *trx = chan->trx;
-  size_t num = chan->num;
+  Transceiver *trx = params->trx;
+  size_t num = params->num;
 
-  delete chan;
+  free(params);
 
   snprintf(thread_name, 16, "RxUpper%zu", num);
   set_selfthread_name(thread_name);
@@ -1154,13 +1160,13 @@
   return NULL;
 }
 
-void *ControlServiceLoopAdapter(TransceiverChannel *chan)
+void *ControlServiceLoopAdapter(TrxChanThParams *params)
 {
   char thread_name[16];
-  Transceiver *trx = chan->trx;
-  size_t num = chan->num;
+  Transceiver *trx = params->trx;
+  size_t num = params->num;
 
-  delete chan;
+  free(params);
 
   snprintf(thread_name, 16, "CtrlService%zu", num);
   set_selfthread_name(thread_name);
@@ -1172,13 +1178,13 @@
   return NULL;
 }
 
-void *TxUpperLoopAdapter(TransceiverChannel *chan)
+void *TxUpperLoopAdapter(TrxChanThParams *params)
 {
   char thread_name[16];
-  Transceiver *trx = chan->trx;
-  size_t num = chan->num;
+  Transceiver *trx = params->trx;
+  size_t num = params->num;
 
-  delete chan;
+  free(params);
 
   snprintf(thread_name, 16, "TxUpper%zu", num);
   set_selfthread_name(thread_name);
diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h
index 8da52d1..18dc5f2 100644
--- a/Transceiver52M/Transceiver.h
+++ b/Transceiver52M/Transceiver.h
@@ -39,19 +39,9 @@
 class Transceiver;
 
 /** Channel descriptor for transceiver object and channel number pair */
-struct TransceiverChannel {
-  TransceiverChannel(Transceiver *trx, int num)
-  {
-    this->trx = trx;
-    this->num = num;
-  }
-
-  ~TransceiverChannel()
-  {
-  }
-
-  Transceiver *trx;
-  size_t num;
+struct TrxChanThParams {
+	Transceiver *trx;
+	size_t num;
 };
 
 /** Internal transceiver state variables */
@@ -248,15 +238,11 @@
   */
   bool driveTxPriorityQueue(size_t chan);
 
-  friend void *RxUpperLoopAdapter(TransceiverChannel *);
-
-  friend void *TxUpperLoopAdapter(TransceiverChannel *);
-
-  friend void *RxLowerLoopAdapter(Transceiver *);
-
-  friend void *TxLowerLoopAdapter(Transceiver *);
-
-  friend void *ControlServiceLoopAdapter(TransceiverChannel *);
+  friend void *RxUpperLoopAdapter(TrxChanThParams *params);
+  friend void *TxUpperLoopAdapter(TrxChanThParams *params);
+  friend void *RxLowerLoopAdapter(Transceiver *transceiver);
+  friend void *TxLowerLoopAdapter(Transceiver *transceiver);
+  friend void *ControlServiceLoopAdapter(TrxChanThParams *params);
 
 
   void reset();
@@ -267,14 +253,14 @@
   void logRxBurst(size_t chan, const struct trx_ul_burst_ind *bi);
 };
 
-void *RxUpperLoopAdapter(TransceiverChannel *);
+void *RxUpperLoopAdapter(TrxChanThParams *params);
 
 /** Main drive threads */
-void *RxLowerLoopAdapter(Transceiver *);
-void *TxLowerLoopAdapter(Transceiver *);
+void *RxLowerLoopAdapter(Transceiver *transceiver);
+void *TxLowerLoopAdapter(Transceiver *transceiver);
 
 /** control message handler thread loop */
-void *ControlServiceLoopAdapter(TransceiverChannel *);
+void *ControlServiceLoopAdapter(TrxChanThParams *params);
 
 /** transmit queueing thread loop */
-void *TxUpperLoopAdapter(TransceiverChannel *);
+void *TxUpperLoopAdapter(TrxChanThParams *params);

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/14898
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I6e3898a8a66520cc5b2a7df9b9ae01b0b272387f
Gerrit-Change-Number: 14898
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190723/cc90e413/attachment.htm>


More information about the gerrit-log mailing list