From 432743b06075192866145b68a7be5ea136f05ea5 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:57:47 -0700 Subject: [PATCH] switched mResults over to a unique_ptr, because resetting the class directly with the default assignment operator broke its mutexes. --- docs/Analyzer_API.md | 15 +++++++-------- src/SimpleSerialAnalyzer.cpp | 13 ++++++------- src/SimpleSerialAnalyzer.h | 4 +++- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/Analyzer_API.md b/docs/Analyzer_API.md index ad1a774..30b4231 100644 --- a/docs/Analyzer_API.md +++ b/docs/Analyzer_API.md @@ -667,7 +667,7 @@ extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); You’ll also need these member variables: ```c++ {YourName}AnalyzerSettings mSettings; -{YourName}AnalyzerResults mResults; +std::unique_ptr<{YourName}AnalyzerResults> mResults; {YourName}SimulationDataGenerator mSimulationDataGenerator; bool mSimulationInitialized; ``` @@ -686,7 +686,6 @@ Your constructor will look something like this {YourName}Analyzer::{YourName}Analyzer() : Analyzer(), mSettings(), -mResults(this, &mSettings), mSimulationInitialized( false ) { SetAnalyzerSettings( &mSettings ); @@ -765,15 +764,15 @@ delete analyzer; ## ```{YourName}Analyzer::WorkerThread()``` Ok, now that everything else is taken care of, let’s look at the most important part of the analyzer in detail. First, we’ll reset our ```AnalyzerResults``` derived object. This is because your analyzer class instance may be re-used for multiple runs, so at the beginning of each run, the generated results must be reset. ```c++ -mResults = {YourName}AnalyzerResults( this, &mSettings ); +mResults.reset( new {YourName}AnalyzerResults( this, &mSettings ) ); ``` Well provide a pointer to our results to the base class: ```c++ -SetAnalyzerResults( &mResults ); +SetAnalyzerResults( mResults.get() ); ``` Let’s indicate which channels we’ll be displaying results on (in the form of bubbles). Usually this will only be one channel. (Except in the case of SPI, where we’ll want to put bubbles on both the MISO and MISO lines.) Only indicate where we will display bubbles – other markup, like tick marks, arrows, etc, are not bubbles, and should not be reported here. ```c++ -mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); +mResults->AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); ``` We’ll probably want to know (and save in a member variable) the sample rate. ```c++ @@ -862,8 +861,8 @@ if( such_and_such_error == true ) frame.mFlags |= SUCH_AND_SUCH_ERROR_FLAG | DISPLAY_AS_ERROR_FLAG; if( such_and_such_warning == true ) frame.mFlags |= SUCH_AND_SUCH_WARNING_FLAG | DISPLAY_AS_WARNING_FLAG; -mResults.AddFrame( frame ); -mResults.CommitResults(); +mResults->AddFrame( frame ); +mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); ``` @@ -886,7 +885,7 @@ void AddMarker( U64 sample_number, MarkerType marker_type, Channel& channel ); ``` For example, from ```SerialAnalyzer.cpp``` : ```c++ -mResults.AddMarker( marker_location, AnalyzerResults::Dot, mSettings.mInputChannel ); +mResults->AddMarker( marker_location, AnalyzerResults::Dot, mSettings.mInputChannel ); ``` Currently, the available graphical artifacts are diff --git a/src/SimpleSerialAnalyzer.cpp b/src/SimpleSerialAnalyzer.cpp index e0ec1f3..ef44917 100644 --- a/src/SimpleSerialAnalyzer.cpp +++ b/src/SimpleSerialAnalyzer.cpp @@ -5,7 +5,6 @@ SimpleSerialAnalyzer::SimpleSerialAnalyzer() : Analyzer2(), mSettings(), - mResults(this, &mSettings), mSimulationInitilized( false ) { SetAnalyzerSettings( &mSettings ); @@ -19,9 +18,9 @@ SimpleSerialAnalyzer::~SimpleSerialAnalyzer() void SimpleSerialAnalyzer::SetupResults() { // SetupResults is called each time the analyzer is run. Because the same instance can be used for multiple runs, we need to clear the results each time. - mResults = SimpleSerialAnalyzerResults( this, &mSettings ); - SetAnalyzerResults( &mResults ); - mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); + mResults.reset(new SimpleSerialAnalyzerResults( this, &mSettings )); + SetAnalyzerResults( mResults.get() ); + mResults->AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); } void SimpleSerialAnalyzer::WorkerThread() @@ -50,7 +49,7 @@ void SimpleSerialAnalyzer::WorkerThread() for( U32 i=0; i<8; i++ ) { //let's put a dot exactly where we sample this bit: - mResults.AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings.mInputChannel ); + mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings.mInputChannel ); if( mSerial->GetBitState() == BIT_HIGH ) data |= mask; @@ -68,8 +67,8 @@ void SimpleSerialAnalyzer::WorkerThread() frame.mStartingSampleInclusive = starting_sample; frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); - mResults.AddFrame( frame ); - mResults.CommitResults(); + mResults->AddFrame( frame ); + mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } } diff --git a/src/SimpleSerialAnalyzer.h b/src/SimpleSerialAnalyzer.h index 43318bd..15ee87d 100644 --- a/src/SimpleSerialAnalyzer.h +++ b/src/SimpleSerialAnalyzer.h @@ -5,6 +5,8 @@ #include "SimpleSerialAnalyzerSettings.h" #include "SimpleSerialAnalyzerResults.h" #include "SimpleSerialSimulationDataGenerator.h" +#include + class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 { public: @@ -22,7 +24,7 @@ public: protected: //vars SimpleSerialAnalyzerSettings mSettings; - SimpleSerialAnalyzerResults mResults; + std::unique_ptr mResults; AnalyzerChannelData* mSerial; SimpleSerialSimulationDataGenerator mSimulationDataGenerator;