From 8514fc07c7e0f62b44dd012db50e2c48d797d181 Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Tue, 13 Jul 2021 18:06:41 +0200 Subject: [PATCH 1/7] Add changes for PERF-301 --- build.sh | 17 +++++++++++++++++ srcCpp/Infrastructure_common.cxx | 10 +++++++--- srcCpp/Infrastructure_common.h | 12 +++++++++--- .../connextDDS/micro/Infrastructure_micro.cxx | 4 ++++ srcCpp/connextDDS/micro/Infrastructure_micro.h | 6 ++++++ srcCpp/connextDDS/pro/Infrastructure_pro.cxx | 3 +++ srcCpp/connextDDS/pro/Infrastructure_pro.h | 3 +++ srcCpp/perftest_cpp.cxx | 4 ++++ srcCpp/perftest_cpp.h | 8 +++++--- srcCpp11/perftest_cpp.cxx | 4 ++++ srcCpp11/perftest_cpp.h | 3 ++- 11 files changed, 64 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 04e2f338..97f8ca03 100755 --- a/build.sh +++ b/build.sh @@ -72,6 +72,10 @@ darwin_shmem_size=419430400 # the native implementation RTI_PERFTEST_NANO_CLOCK=0 +# For C++ Classic, variable to control if we want to force the use +# of the C++11 infrastructure +RTI_USE_CPP_11_INFRASTRUCTURE=0 + # We will use some colors to improve visibility of errors and information RED='\033[0;31m' GREEN='\033[0;32m' @@ -429,6 +433,11 @@ function additional_defines_calculation() if [ "${1}" = "CppTraditional" ]; then additional_defines=${additional_defines}" DRTI_LANGUAGE_CPP_TRADITIONAL" + if [ "${RTI_USE_CPP_11_INFRASTRUCTURE}" == "1" ]; then + echo -e "${INFO_TAG} Force using C++11 and C++11 Infrastructure." + additional_defines=${additional_defines}" DRTI_USE_CPP_11_INFRASTRUCTURE" + fi + if [ "${RTI_PERFTEST_NANO_CLOCK}" == "1" ]; then additional_defines=${additional_defines}" DRTI_PERFTEST_NANO_CLOCK" fi @@ -486,6 +495,11 @@ function additional_defines_calculation_micro() additional_defines=${additional_defines}" DRTI_PERFTEST_NANO_CLOCK" fi + if [ "${RTI_USE_CPP_11_INFRASTRUCTURE}" == "1" ]; then + echo -e "${INFO_TAG} Force using C++11 and C++11 Infrastructure." + additional_defines=${additional_defines}" DRTI_USE_CPP_11_INFRASTRUCTURE" + fi + if [ "${USE_SECURE_LIBS}" == "1" ]; then additional_defines="${additional_defines} RTI_SECURE_PERFTEST" @@ -1477,6 +1491,9 @@ while [ "$1" != "" ]; do --ns-resolution) RTI_PERFTEST_NANO_CLOCK=1 ;; + --force-c++11-infrastructure) + RTI_USE_CPP_11_INFRASTRUCTURE=1 + ;; --dynamic) STATIC_DYNAMIC=dynamic ;; diff --git a/srcCpp/Infrastructure_common.cxx b/srcCpp/Infrastructure_common.cxx index b4f04359..5466f609 100644 --- a/srcCpp/Infrastructure_common.cxx +++ b/srcCpp/Infrastructure_common.cxx @@ -17,7 +17,7 @@ * which will make us compatible with less OSs. In other cases we do need a * implementation for these classes. */ -#if !defined(PERFTEST_RTI_MICRO) && !defined(PERFTEST_RTI_PRO) +#if defined(RTI_USE_CPP_11_INFRASTRUCTURE) || (!defined(PERFTEST_RTI_MICRO) && !defined(PERFTEST_RTI_PRO)) /********************************************************************/ /* Perftest Semaphore class */ @@ -64,9 +64,10 @@ void PerftestMutex_delete(std::mutex* mutex) delete mutex; } -void PerftestMutex_give(std::mutex* mutex) +bool PerftestMutex_give(std::mutex* mutex) { mutex->unlock(); + return true; } bool PerftestMutex_take(std::mutex* mutex) @@ -114,6 +115,7 @@ void PerftestClock::sleep(const struct DDS_Duration_t& sleep_period) NDDSUtility::sleep(sleep_period); } +#if !defined(PERFTEST_RTI_MICRO) && !defined(PERFTEST_RTI_PRO) void NDDSUtility::sleep(const struct DDS_Duration_t &durationIn) { std::this_thread::sleep_for( @@ -164,6 +166,8 @@ NDDSUtility::get_spin_per_microsecond(unsigned int precision) return (unsigned long long) (iterations * spinCount) / usec; } +#endif //#if !defined(PERFTEST_RTI_MICRO) && !defined(PERFTEST_RTI_PRO) + /********************************************************************/ /* Perftest Thread class */ @@ -172,7 +176,7 @@ struct PerftestThreadOnSpawnedMethod ThreadOnSpawnedMethod method; void *thread_param; -} +}; PerftestThread* PerftestThread_new( const char *name, diff --git a/srcCpp/Infrastructure_common.h b/srcCpp/Infrastructure_common.h index d975b663..c8fcc9a7 100644 --- a/srcCpp/Infrastructure_common.h +++ b/srcCpp/Infrastructure_common.h @@ -47,11 +47,14 @@ * which will make us compatible with less OSs. In other cases we do need a * implementation for these classes. */ + #ifdef PERFTEST_RTI_PRO #include "Infrastructure_pro.h" #elif PERFTEST_RTI_MICRO #include "Infrastructure_micro.h" -#else // Other DDS Middleware +#endif + +#if defined(RTI_USE_CPP_11_INFRASTRUCTURE) || (!defined(PERFTEST_RTI_MICRO) && !defined(PERFTEST_RTI_PRO)) #include #include @@ -64,10 +67,11 @@ * generated variable for a string is different. We need to move it to a generic * place and remove it from here in the future. */ - +#if !defined(PERFTEST_RTI_PRO) && !defined(PERFTEST_RTI_MICRO) static const char *const THROUGHPUT_TOPIC_NAME = "Throughput"; static const char *const LATENCY_TOPIC_NAME = "Latency"; static const char *const ANNOUNCEMENT_TOPIC_NAME = "Announcement"; +#endif /********************************************************************/ @@ -128,7 +132,7 @@ bool PerftestSemaphore_take(PerftestSemaphore *semaphore, int timeout); #define PerftestMutex std::mutex PerftestMutex *PerftestMutex_new(); void PerftestMutex_delete(std::mutex *mutex); -void PerftestMutex_give(std::mutex *mutex); +bool PerftestMutex_give(std::mutex *mutex); bool PerftestMutex_take(std::mutex *mutex); /********************************************************************/ @@ -169,6 +173,7 @@ PerftestThread *PerftestThread_new( void PerftestThread_delete(PerftestThread *thread); +#if !defined(PERFTEST_RTI_PRO) && !defined(PERFTEST_RTI_MICRO) struct DDS_Duration_t { int sec; unsigned int nanosec; @@ -185,6 +190,7 @@ class NDDSUtility { static unsigned long long int get_spin_per_microsecond(unsigned int precision = 100); }; +#endif #endif diff --git a/srcCpp/connextDDS/micro/Infrastructure_micro.cxx b/srcCpp/connextDDS/micro/Infrastructure_micro.cxx index e43c41db..9f3d3aec 100644 --- a/srcCpp/connextDDS/micro/Infrastructure_micro.cxx +++ b/srcCpp/connextDDS/micro/Infrastructure_micro.cxx @@ -7,6 +7,8 @@ #include "Infrastructure_common.h" +#ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /********************************************************************/ /* Perftest Clock class */ @@ -152,6 +154,8 @@ void PerftestThread_delete(struct PerftestThread* thread) } } +#endif //#ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /********************************************************************/ /* Transport related functions */ diff --git a/srcCpp/connextDDS/micro/Infrastructure_micro.h b/srcCpp/connextDDS/micro/Infrastructure_micro.h index c8e34708..19d02003 100644 --- a/srcCpp/connextDDS/micro/Infrastructure_micro.h +++ b/srcCpp/connextDDS/micro/Infrastructure_micro.h @@ -26,6 +26,9 @@ #include + +#ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /********************************************************************/ /* * In order to unify the implementations for Micro and Pro, we wrap the @@ -100,6 +103,9 @@ struct PerftestThread* PerftestThread_new( void PerftestThread_delete(struct PerftestThread* thread); + +#endif // #ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /********************************************************************/ /* Transport Related functions */ diff --git a/srcCpp/connextDDS/pro/Infrastructure_pro.cxx b/srcCpp/connextDDS/pro/Infrastructure_pro.cxx index 6222496e..d7b1f84c 100644 --- a/srcCpp/connextDDS/pro/Infrastructure_pro.cxx +++ b/srcCpp/connextDDS/pro/Infrastructure_pro.cxx @@ -10,6 +10,8 @@ #include using namespace std; +#ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /* Perftest Clock class */ PerftestClock::PerftestClock() @@ -86,6 +88,7 @@ struct PerftestThread* PerftestThread_new( return thread; } +#endif //#ifndef RTI_USE_CPP_11_INFRASTRUCTURE /********************************************************************/ /* Transport Related functions */ diff --git a/srcCpp/connextDDS/pro/Infrastructure_pro.h b/srcCpp/connextDDS/pro/Infrastructure_pro.h index aaa59e72..49687c8d 100644 --- a/srcCpp/connextDDS/pro/Infrastructure_pro.h +++ b/srcCpp/connextDDS/pro/Infrastructure_pro.h @@ -31,6 +31,8 @@ #include +#ifndef RTI_USE_CPP_11_INFRASTRUCTURE + /* * In order to unify the implementations for Micro and Pro, we wrap the * semaphores to a common PerftestSemaphore implementation. @@ -123,6 +125,7 @@ struct PerftestThread* PerftestThread_new( RTIOsapiThreadOnSpawnedMethod method, void *threadParam); +#endif //#ifndef RTI_USE_CPP_11_INFRASTRUCTURE /********************************************************************/ /* Transport Related functions */ diff --git a/srcCpp/perftest_cpp.cxx b/srcCpp/perftest_cpp.cxx index 113ef806..8e2a5364 100644 --- a/srcCpp/perftest_cpp.cxx +++ b/srcCpp/perftest_cpp.cxx @@ -89,6 +89,10 @@ const unsigned long long numIterDefaultLatencyTest = 10000000; */ int main(int argc, char *argv[]) { + + perftest_cpp::_testCompleted = false; + perftest_cpp::_testCompleted_scan = true; // In order to enter into the scan mode + try { perftest_cpp app; return app.Run(argc, argv); diff --git a/srcCpp/perftest_cpp.h b/srcCpp/perftest_cpp.h index 9035f063..84d5bfde 100644 --- a/srcCpp/perftest_cpp.h +++ b/srcCpp/perftest_cpp.h @@ -63,16 +63,18 @@ class perftest_cpp // Priorities for the threads used by perftest and domain participant ThreadPriorities _threadPriorities; + + static void Timeout(); + static void Timeout_scan(); + + public: /* * The following members are used in a static callback * and so they have to be static */ static bool _testCompleted; static bool _testCompleted_scan; - static void Timeout(); - static void Timeout_scan(); - public: int subID; bool printIntervals; bool showCpu; diff --git a/srcCpp11/perftest_cpp.cxx b/srcCpp11/perftest_cpp.cxx index 56c829e0..e2f866ee 100755 --- a/srcCpp11/perftest_cpp.cxx +++ b/srcCpp11/perftest_cpp.cxx @@ -108,6 +108,10 @@ const unsigned long long numIterDefaultLatencyTest = 10000000; */ int main(int argc, char *argv[]) { + + perftest_cpp::_testCompleted = false; + perftest_cpp::_testCompleted_scan = true; // In order to enter into the scan mode + try { perftest_cpp app; return app.Run(argc, argv); diff --git a/srcCpp11/perftest_cpp.h b/srcCpp11/perftest_cpp.h index f2c5d97f..341fcb60 100755 --- a/srcCpp11/perftest_cpp.h +++ b/srcCpp11/perftest_cpp.h @@ -103,12 +103,13 @@ class perftest_cpp ThreadPriorities _threadPriorities; + public: + /* The following three members are used in a static callback and so they have to be static */ static bool _testCompleted; static bool _testCompleted_scan; - public: /* * Number of bytes sent in messages besides user data. This value is * calculated at run time. From e9e8c17afc0cf2c621845fd6a3bdf8833ea74b94 Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Mon, 19 Jul 2021 10:58:14 +0200 Subject: [PATCH 2/7] Add documentation --- srcDoc/release_notes.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/srcDoc/release_notes.rst b/srcDoc/release_notes.rst index aee0481d..1d31f83c 100644 --- a/srcDoc/release_notes.rst +++ b/srcDoc/release_notes.rst @@ -42,6 +42,8 @@ Switched to C++11 clock implementation in Modern C++ API |enhancedTag| To simplify the *Modern C++* API implementation, *RTI Perftest* now uses the *C++11* clocks, instead of the ones provided by *RTI Connext DDS*. +This resolves the issue ``PERF-300``. + What's Fixed in Develop ~~~~~~~~~~~~~~~~~~~~~~~ @@ -83,6 +85,17 @@ added to the verbosity for customers testing in these OSes: Now this warning is displayed only if ``-cpu`` is entered as a command-line option. +Crash in *VxWorks kernel Mode* and incorrect behavior when running Perftest multiple times |fixedTag| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +In previous versions of *RTI Perftest*, the Traditional and Modern C++ API implementations +would fail to run multiple times on *VxWorks* in *kernel Mode* if the ``-executionTime`` +command-line option was provided. This was due to an issue where some static variables +were initialized when loading the libraries, but not reset when calling the initialization +functions. Hence, in the second run having the last value from the previous run. + +This resolves the issue ``PERF-301``. + Deprecations in Develop ~~~~~~~~~~~~~~~~~~~~~~~ From 4c8ff5b300662e325a0c5903e5e315d3a6ca0811 Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Mon, 19 Jul 2021 11:31:43 +0200 Subject: [PATCH 3/7] Add changes in sample loan and reader destruction --- srcCpp11/RTIDDSImpl.cxx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/srcCpp11/RTIDDSImpl.cxx b/srcCpp11/RTIDDSImpl.cxx index bc291e21..f0af0e80 100755 --- a/srcCpp11/RTIDDSImpl.cxx +++ b/srcCpp11/RTIDDSImpl.cxx @@ -907,7 +907,6 @@ class ReceiverListenerBase: public dds::sub::NoOpDataReaderListener { protected: TestMessage _message; IMessagingCB *_callback; - dds::sub::LoanedSamples samples; public: ReceiverListenerBase(IMessagingCB *callback) : @@ -926,11 +925,11 @@ class ReceiverListener: public ReceiverListenerBase { void on_data_available(dds::sub::DataReader &reader) { - this->samples = reader.take(); + dds::sub::LoanedSamples samples = reader.take(); - for (unsigned int i = 0; i < this->samples.length(); ++i) { - if (this->samples[i].info().valid()) { - const T & sample = this->samples[i].data(); + for (unsigned int i = 0; i < samples.length(); ++i) { + if (samples[i].info().valid()) { + const T & sample = samples[i].data(); this->_message.entity_id = sample.entity_id(); this->_message.seq_num = sample.seq_num(); this->_message.timestamp_sec = sample.timestamp_sec(); @@ -1014,12 +1013,12 @@ class DynamicDataReceiverListener: public ReceiverListenerBase { void on_data_available(dds::sub::DataReader &reader) { - this->samples = reader.take(); + dds::sub::LoanedSamples samples = reader.take(); - for (unsigned int i = 0; i < this->samples.length(); ++i) { - if (this->samples[i].info().valid()) { + for (unsigned int i = 0; i < samples.length(); ++i) { + if (samples[i].info().valid()) { DynamicData& sample = - const_cast(this->samples[i].data()); + const_cast(samples[i].data()); this->_message.entity_id = sample.value( DynamicDataMembersId::GetInstance().at("entity_id")); this->_message.seq_num = sample.value( @@ -1091,7 +1090,7 @@ class RTISubscriberBase: public IMessagingReader { } void shutdown() { - _reader.listener(NULL, dds::core::status::StatusMask::none()); + _reader.close(); if (_readerListener != NULL) { delete(_readerListener); } From 05136a91d826bb08e3cf9236b5354abec1b8aeec Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Wed, 21 Jul 2021 13:55:26 +0200 Subject: [PATCH 4/7] Add documentation --- srcDoc/release_notes.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/srcDoc/release_notes.rst b/srcDoc/release_notes.rst index 1c301ee7..cb21b014 100644 --- a/srcDoc/release_notes.rst +++ b/srcDoc/release_notes.rst @@ -107,6 +107,24 @@ Therefore, the second run's last value came from the previous run. This fix resolves the issue ``PERF-301``. +Fix issue in the *Modern C++* API Implementation not returning loaned memory for samples fast enough |fixedTag| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +In previous versions of the *Modern C++* API Implementation for *RTI Perftest*, +we found that we were retaining loaned samples after reading them from the reader +for too long. In certain scenarios (where other errors should be also involved) +this could lead to issues deleting the readers at the end of the test, showing errors +similar to the following ones: + +.. code-block:: console + + [D0047|Sub(80000009)|T=Latency|DELETE Reader] PRESPsService_destroyLocalEndpointWithCursor:outstanding loans <<< + [D0047|Sub(80000009)|T=Latency|DELETE Reader] PRESPsService_destroyLocalEndpoint:!delete local reader + [D0047|Sub(80000009)|T=Latency|DELETE Reader] DDS_DataReader_deleteI:!delete PRESLocalEndpoint + [D0047|Sub(80000009)|T=Latency|DELETE Reader] DDS_Subscriber_delete_datareader:!delete reader + +This fix resolves the issue ``PERF-312``. + Deprecations in Develop ~~~~~~~~~~~~~~~~~~~~~~~ From 96cd2c3e4dacccd7a814ca7f66dc4dfb744eae2e Mon Sep 17 00:00:00 2001 From: rkorte Date: Wed, 21 Jul 2021 13:56:23 -0700 Subject: [PATCH 5/7] PERF-312: writer's edits to release notes addition --- srcDoc/release_notes.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/srcDoc/release_notes.rst b/srcDoc/release_notes.rst index cb21b014..18ca7fee 100644 --- a/srcDoc/release_notes.rst +++ b/srcDoc/release_notes.rst @@ -107,14 +107,14 @@ Therefore, the second run's last value came from the previous run. This fix resolves the issue ``PERF-301``. -Fix issue in the *Modern C++* API Implementation not returning loaned memory for samples fast enough |fixedTag| -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -In previous versions of the *Modern C++* API Implementation for *RTI Perftest*, -we found that we were retaining loaned samples after reading them from the reader -for too long. In certain scenarios (where other errors should be also involved) -this could lead to issues deleting the readers at the end of the test, showing errors -similar to the following ones: +*Modern C++* API implementation not returning loaned memory for samples fast enough |fixedTag| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +The *Modern C++* API Implementation for *RTI Perftest* retained loaned samples +for too long after reading them from the *DataReader*. In some scenarios (where +other errors would also be involved), retaining the loaned samples for too long +led to issues deleting the *DataReaders* at the end of the test, showing +errors similar to the following: .. code-block:: console From b03e278c64c50b66329933ddd964f7f304a31cf7 Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Fri, 23 Jul 2021 11:06:38 +0200 Subject: [PATCH 6/7] Add CR changes --- srcCpp11/RTIDDSImpl.cxx | 209 ++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 107 deletions(-) diff --git a/srcCpp11/RTIDDSImpl.cxx b/srcCpp11/RTIDDSImpl.cxx index f0af0e80..bcbc544e 100755 --- a/srcCpp11/RTIDDSImpl.cxx +++ b/srcCpp11/RTIDDSImpl.cxx @@ -927,15 +927,15 @@ class ReceiverListener: public ReceiverListenerBase { dds::sub::LoanedSamples samples = reader.take(); - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - const T & sample = samples[i].data(); - this->_message.entity_id = sample.entity_id(); - this->_message.seq_num = sample.seq_num(); - this->_message.timestamp_sec = sample.timestamp_sec(); - this->_message.timestamp_usec = sample.timestamp_usec(); - this->_message.latency_ping = sample.latency_ping(); - this->_message.size = (int) sample.bin_data().size(); + for (const auto& sample : samples) { + if (sample.info().valid()) { + const T & sampleData = sample.data(); + this->_message.entity_id = sampleData.entity_id(); + this->_message.seq_num = sampleData.seq_num(); + this->_message.timestamp_sec = sampleData.timestamp_sec(); + this->_message.timestamp_usec = sampleData.timestamp_usec(); + this->_message.latency_ping = sampleData.latency_ping(); + this->_message.size = (int) sampleData.bin_data().size(); //this->_message.data = sample.bin_data(); this->_callback->process_message(this->_message); } @@ -972,34 +972,34 @@ class ReceiverListener: public ReceiverListenerBase { _checkConsistency(checkConsistency){ } - /** - * Take a new sample and process it using FlatData API. - * - * @param reader is the reader to take samples from - */ - void on_data_available(dds::sub::DataReader &reader) { - dds::sub::LoanedSamples samples = reader.take(); - - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - const T &sample = samples[i].data(); - ConstOffset message = sample.root(); - - this->_message.entity_id = message.entity_id(); - this->_message.seq_num = message.seq_num(); - this->_message.timestamp_sec = message.timestamp_sec(); - this->_message.timestamp_usec = message.timestamp_usec(); - this->_message.latency_ping = message.latency_ping(); - this->_message.size = message.bin_data().element_count(); - // bin_data should be retrieved here - - // Check that the sample was not modified on the publisher side when using Zero Copy. - if (_isZeroCopy && _checkConsistency) { - if (!reader->is_data_consistent(samples[i])) continue; - } - - this->_callback->process_message(this->_message); - } + /** + * Take a new sample and process it using FlatData API. + * + * @param reader is the reader to take samples from + */ + void on_data_available(dds::sub::DataReader &reader) { + + dds::sub::LoanedSamples samples = reader.take(); + + for (const auto& sample : samples) { + if (sample.info().valid()) { + const T &sampleData = sample.data(); + ConstOffset message = sampleData.root(); + this->_message.entity_id = message.entity_id(); + this->_message.seq_num = message.seq_num(); + this->_message.timestamp_sec = message.timestamp_sec(); + this->_message.timestamp_usec = message.timestamp_usec(); + this->_message.latency_ping = message.latency_ping(); + this->_message.size = message.bin_data().element_count(); + // bin_data should be retrieved here + + // Check that the sample was not modified on the publisher side when using Zero Copy. + if (_isZeroCopy && _checkConsistency) { + if (!reader->is_data_consistent(sample)) continue; + } + + this->_callback->process_message(this->_message); + } } } }; @@ -1015,24 +1015,24 @@ class DynamicDataReceiverListener: public ReceiverListenerBase { dds::sub::LoanedSamples samples = reader.take(); - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - DynamicData& sample = - const_cast(samples[i].data()); - this->_message.entity_id = sample.value( + for (const auto& sample : samples) { + if (sample.info().valid()) { + DynamicData& sampleData = + const_cast(sample.data()); + this->_message.entity_id = sampleData.value( DynamicDataMembersId::GetInstance().at("entity_id")); - this->_message.seq_num = sample.value( + this->_message.seq_num = sampleData.value( DynamicDataMembersId::GetInstance().at("seq_num")); - this->_message.timestamp_sec = sample.value( + this->_message.timestamp_sec = sampleData.value( DynamicDataMembersId::GetInstance().at("timestamp_sec")); - this->_message.timestamp_usec = sample.value( + this->_message.timestamp_usec = sampleData.value( DynamicDataMembersId::GetInstance().at("timestamp_usec")); - this->_message.latency_ping = sample.value( + this->_message.latency_ping = sampleData.value( DynamicDataMembersId::GetInstance().at("latency_ping")); - this->_message.size = (int)(sample.get_values( + this->_message.size = (int)(sampleData.get_values( DynamicDataMembersId::GetInstance().at("bin_data")).size()); - //_message.data = sample.bin_data(); + //_message.data = sampleData.bin_data(); _callback->process_message(this->_message); } } @@ -1170,16 +1170,16 @@ class RTISubscriber: public RTISubscriberBase { this->_waitset.dispatch(dds::core::Duration::infinite()); dds::sub::LoanedSamples samples = this->_reader.take(); - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - const T & sample = samples[i].data(); - this->_message.entity_id = sample.entity_id(); - this->_message.seq_num = sample.seq_num(); - this->_message.timestamp_sec = sample.timestamp_sec(); - this->_message.timestamp_usec = sample.timestamp_usec(); - this->_message.latency_ping = sample.latency_ping(); - this->_message.size = (int) sample.bin_data().size(); - //_message.data = sample.bin_data(); + for (const auto& sample : samples) { + if (sample.info().valid()) { + const T & sampleData = sample.data(); + this->_message.entity_id = sampleData.entity_id(); + this->_message.seq_num = sampleData.seq_num(); + this->_message.timestamp_sec = sampleData.timestamp_sec(); + this->_message.timestamp_usec = sampleData.timestamp_usec(); + this->_message.latency_ping = sampleData.latency_ping(); + this->_message.size = (int) sampleData.bin_data().size(); + //_message.data = sampleData.bin_data(); listener->process_message(this->_message); } @@ -1283,30 +1283,30 @@ class RTISubscriber: public RTISubscriberBase { void ReceiveAndProccess(IMessagingCB *listener) { while (!listener->end_test) { - this->_waitset.dispatch(dds::core::Duration::infinite()); - dds::sub::LoanedSamples samples = this->_reader.take(); + this->_waitset.dispatch(dds::core::Duration::infinite()); + dds::sub::LoanedSamples samples = this->_reader.take(); - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - const T &message_sample = samples[i].data(); - ConstOffset message = message_sample.root(); - - this->_message.entity_id = message.entity_id(); - this->_message.seq_num = message.seq_num(); - this->_message.timestamp_sec = message.timestamp_sec(); - this->_message.timestamp_usec = message.timestamp_usec(); - this->_message.latency_ping = message.latency_ping(); - this->_message.size = message.bin_data().element_count(); - //_message.data = message.bin_data(); - - // Check that the sample was not modified on the publisher side when using Zero Copy. - if (_isZeroCopy && _checkConsistency) { - if (!this->_reader->is_data_consistent(samples[i])) continue; - } - - listener->process_message(this->_message); - } - } + for (const auto& sample : samples) { + if (sample.info().valid()) { + const T &message_sample = sample.data(); + ConstOffset message = message_sample.root(); + + this->_message.entity_id = message.entity_id(); + this->_message.seq_num = message.seq_num(); + this->_message.timestamp_sec = message.timestamp_sec(); + this->_message.timestamp_usec = message.timestamp_usec(); + this->_message.latency_ping = message.latency_ping(); + this->_message.size = message.bin_data().element_count(); + //_message.data = message.bin_data(); + + // Check that the sample was not modified on the publisher side when using Zero Copy. + if (_isZeroCopy && _checkConsistency) { + if (!this->_reader->is_data_consistent(sample)) continue; + } + + listener->process_message(this->_message); + } + } } } }; @@ -1375,35 +1375,30 @@ class RTIDynamicDataSubscriber: public RTISubscriberBase { return NULL; } - void ReceiveAndProccess(IMessagingCB *listener) { + void ReceiveAndProccess(IMessagingCB *listener) + { while (!listener->end_test) { - this->_waitset.dispatch(dds::core::Duration::infinite()); - dds::sub::LoanedSamples samples = - this->_reader.take(); - - for (unsigned int i = 0; i < samples.length(); ++i) { - if (samples[i].info().valid()) { - DynamicData& sample = - const_cast( - samples[i].data()); - this->_message.entity_id = sample.value( - DynamicDataMembersId::GetInstance().at( - "entity_id")); - this->_message.seq_num = sample.value( - DynamicDataMembersId::GetInstance().at( - "seq_num")); - this->_message.timestamp_sec = sample.value( - DynamicDataMembersId::GetInstance().at( - "timestamp_sec")); - this->_message.timestamp_usec = sample.value( - DynamicDataMembersId::GetInstance().at( - "timestamp_usec")); - this->_message.latency_ping = sample.value( + dds::sub::LoanedSamples samples = this->_reader.take(); + + for (const auto &sample : samples) { + if (sample.info().valid()) { + DynamicData &sampleData = + const_cast(sample.data()); + this->_message.entity_id = sampleData.value( + DynamicDataMembersId::GetInstance().at("entity_id")); + this->_message.seq_num = sampleData.value( + DynamicDataMembersId::GetInstance().at("seq_num")); + this->_message.timestamp_sec = sampleData.value( + DynamicDataMembersId::GetInstance().at("timestamp_sec")); + this->_message.timestamp_usec = sampleData.value( + DynamicDataMembersId::GetInstance().at("timestamp_usec")); + this->_message.latency_ping = sampleData.value( DynamicDataMembersId::GetInstance().at("latency_ping")); - this->_message.size = (int)(sample.get_values( - DynamicDataMembersId::GetInstance().at("bin_data")).size()); - //_message.data = sample.bin_data(); + this->_message.size = + (int) (sampleData.get_values( + DynamicDataMembersId::GetInstance().at("bin_data")).size()); + //_message.data = sampleData.bin_data(); listener->process_message(this->_message); } } From 404be12badd6879c9908618b6d6989344ed6413b Mon Sep 17 00:00:00 2001 From: Javier Morales Date: Sat, 24 Jul 2021 08:53:50 +0200 Subject: [PATCH 7/7] CR feedback --- srcCpp11/RTIDDSImpl.cxx | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/srcCpp11/RTIDDSImpl.cxx b/srcCpp11/RTIDDSImpl.cxx index bcbc544e..081ea405 100755 --- a/srcCpp11/RTIDDSImpl.cxx +++ b/srcCpp11/RTIDDSImpl.cxx @@ -927,15 +927,15 @@ class ReceiverListener: public ReceiverListenerBase { dds::sub::LoanedSamples samples = reader.take(); - for (const auto& sample : samples) { + for (const auto &sample : samples) { if (sample.info().valid()) { - const T & sampleData = sample.data(); - this->_message.entity_id = sampleData.entity_id(); - this->_message.seq_num = sampleData.seq_num(); - this->_message.timestamp_sec = sampleData.timestamp_sec(); - this->_message.timestamp_usec = sampleData.timestamp_usec(); - this->_message.latency_ping = sampleData.latency_ping(); - this->_message.size = (int) sampleData.bin_data().size(); + const T &data = sample.data(); + this->_message.entity_id = data.entity_id(); + this->_message.seq_num = data.seq_num(); + this->_message.timestamp_sec = data.timestamp_sec(); + this->_message.timestamp_usec = data.timestamp_usec(); + this->_message.latency_ping = data.latency_ping(); + this->_message.size = (int) data.bin_data().size(); //this->_message.data = sample.bin_data(); this->_callback->process_message(this->_message); } @@ -981,10 +981,10 @@ class ReceiverListener: public ReceiverListenerBase { dds::sub::LoanedSamples samples = reader.take(); - for (const auto& sample : samples) { + for (const auto &sample : samples) { if (sample.info().valid()) { - const T &sampleData = sample.data(); - ConstOffset message = sampleData.root(); + const T &data = sample.data(); + ConstOffset message = data.root(); this->_message.entity_id = message.entity_id(); this->_message.seq_num = message.seq_num(); this->_message.timestamp_sec = message.timestamp_sec(); @@ -1015,24 +1015,24 @@ class DynamicDataReceiverListener: public ReceiverListenerBase { dds::sub::LoanedSamples samples = reader.take(); - for (const auto& sample : samples) { + for (const auto &sample : samples) { if (sample.info().valid()) { - DynamicData& sampleData = + const DynamicData &data = const_cast(sample.data()); - this->_message.entity_id = sampleData.value( + this->_message.entity_id = data.value( DynamicDataMembersId::GetInstance().at("entity_id")); - this->_message.seq_num = sampleData.value( + this->_message.seq_num = data.value( DynamicDataMembersId::GetInstance().at("seq_num")); - this->_message.timestamp_sec = sampleData.value( + this->_message.timestamp_sec = data.value( DynamicDataMembersId::GetInstance().at("timestamp_sec")); - this->_message.timestamp_usec = sampleData.value( + this->_message.timestamp_usec = data.value( DynamicDataMembersId::GetInstance().at("timestamp_usec")); - this->_message.latency_ping = sampleData.value( + this->_message.latency_ping = data.value( DynamicDataMembersId::GetInstance().at("latency_ping")); - this->_message.size = (int)(sampleData.get_values( + this->_message.size = (int)(data.get_values( DynamicDataMembersId::GetInstance().at("bin_data")).size()); - //_message.data = sampleData.bin_data(); + //_message.data = data.bin_data(); _callback->process_message(this->_message); } } @@ -1148,7 +1148,7 @@ class RTISubscriber: public RTISubscriberBase { continue; } - const T& data = samples[this->_data_idx].data(); + const T &data = samples[this->_data_idx].data(); this->_message.entity_id = data.entity_id(); this->_message.seq_num = data.seq_num(); this->_message.timestamp_sec = data.timestamp_sec(); @@ -1170,16 +1170,16 @@ class RTISubscriber: public RTISubscriberBase { this->_waitset.dispatch(dds::core::Duration::infinite()); dds::sub::LoanedSamples samples = this->_reader.take(); - for (const auto& sample : samples) { + for (const auto &sample : samples) { if (sample.info().valid()) { - const T & sampleData = sample.data(); - this->_message.entity_id = sampleData.entity_id(); - this->_message.seq_num = sampleData.seq_num(); - this->_message.timestamp_sec = sampleData.timestamp_sec(); - this->_message.timestamp_usec = sampleData.timestamp_usec(); - this->_message.latency_ping = sampleData.latency_ping(); - this->_message.size = (int) sampleData.bin_data().size(); - //_message.data = sampleData.bin_data(); + const T &data = sample.data(); + this->_message.entity_id = data.entity_id(); + this->_message.seq_num = data.seq_num(); + this->_message.timestamp_sec = data.timestamp_sec(); + this->_message.timestamp_usec = data.timestamp_usec(); + this->_message.latency_ping = data.latency_ping(); + this->_message.size = (int) data.bin_data().size(); + //_message.data = data.bin_data(); listener->process_message(this->_message); } @@ -1286,7 +1286,7 @@ class RTISubscriber: public RTISubscriberBase { this->_waitset.dispatch(dds::core::Duration::infinite()); dds::sub::LoanedSamples samples = this->_reader.take(); - for (const auto& sample : samples) { + for (const auto &sample : samples) { if (sample.info().valid()) { const T &message_sample = sample.data(); ConstOffset message = message_sample.root(); @@ -1354,7 +1354,7 @@ class RTIDynamicDataSubscriber: public RTISubscriberBase { continue; } - DynamicData& sample = const_cast( + DynamicData &sample = const_cast( samples[this->_data_idx].data()); this->_message.entity_id = sample.value( DynamicDataMembersId::GetInstance().at("entity_id")); @@ -1383,22 +1383,22 @@ class RTIDynamicDataSubscriber: public RTISubscriberBase { for (const auto &sample : samples) { if (sample.info().valid()) { - DynamicData &sampleData = + const DynamicData &data = const_cast(sample.data()); - this->_message.entity_id = sampleData.value( + this->_message.entity_id = data.value( DynamicDataMembersId::GetInstance().at("entity_id")); - this->_message.seq_num = sampleData.value( + this->_message.seq_num = data.value( DynamicDataMembersId::GetInstance().at("seq_num")); - this->_message.timestamp_sec = sampleData.value( + this->_message.timestamp_sec = data.value( DynamicDataMembersId::GetInstance().at("timestamp_sec")); - this->_message.timestamp_usec = sampleData.value( + this->_message.timestamp_usec = data.value( DynamicDataMembersId::GetInstance().at("timestamp_usec")); - this->_message.latency_ping = sampleData.value( + this->_message.latency_ping = data.value( DynamicDataMembersId::GetInstance().at("latency_ping")); this->_message.size = - (int) (sampleData.get_values( + (int) (data.get_values( DynamicDataMembersId::GetInstance().at("bin_data")).size()); - //_message.data = sampleData.bin_data(); + //_message.data = data.bin_data(); listener->process_message(this->_message); } } @@ -1896,7 +1896,7 @@ IMessagingWriter *RTIDDSImpl::create_writer(const std::string &topic_name) _PM); } else { - const dds::core::xtypes::StructType& type = + const dds::core::xtypes::StructType &type = rti::topic::dynamic_type::get(); dds::topic::Topic topic( _participant, @@ -2069,7 +2069,7 @@ IMessagingReader *RTIDDSImpl::create_reader( _PM); } else { - const dds::core::xtypes::StructType& type = + const dds::core::xtypes::StructType &type = rti::topic::dynamic_type::get(); dds::topic::Topic topic( _participant,