KiCad PCB EDA Suite
FOOTPRINT_ASYNC_LOADER Class Reference

This class can be used to populate a FOOTPRINT_LIST asynchronously. More...

#include <footprint_info.h>

Public Member Functions

 FOOTPRINT_ASYNC_LOADER ()
 Construct an asynchronous loader. More...
 
 ~FOOTPRINT_ASYNC_LOADER ()
 
void SetList (FOOTPRINT_LIST *aList)
 Assign a FOOTPRINT_LIST to the loader. More...
 
void Start (FP_LIB_TABLE *aTable, wxString const *aNickname=nullptr, unsigned aNThreads=DEFAULT_THREADS)
 Launch the worker threads. More...
 
bool Join ()
 Wait until the worker threads are finished, and then perform any required single-threaded finishing on the list. More...
 
void Abort ()
 Safely stop the current process. More...
 

Static Public Attributes

static constexpr unsigned DEFAULT_THREADS = 6
 Default number of worker threads. More...
 

Private Attributes

FOOTPRINT_LISTm_list
 
std::string m_last_table
 
int m_total_libs
 

Friends

class FOOTPRINT_LIST
 
class FOOTPRINT_LIST_IMPL
 

Detailed Description

This class can be used to populate a FOOTPRINT_LIST asynchronously.

Constructing one, calling .Start(), then waiting until it reports completion is equivalent to calling FOOTPRINT_LIST::ReadFootprintFiles().

Definition at line 317 of file footprint_info.h.

Constructor & Destructor Documentation

◆ FOOTPRINT_ASYNC_LOADER()

FOOTPRINT_ASYNC_LOADER::FOOTPRINT_ASYNC_LOADER ( )

Construct an asynchronous loader.

Definition at line 153 of file footprint_info.cpp.

153  : m_list( nullptr )
154 {
155  m_total_libs = 0;
156 }
FOOTPRINT_LIST * m_list

References m_total_libs.

◆ ~FOOTPRINT_ASYNC_LOADER()

FOOTPRINT_ASYNC_LOADER::~FOOTPRINT_ASYNC_LOADER ( )

Definition at line 159 of file footprint_info.cpp.

160 {
161  // This is NOP if the load has finished
162  Abort();
163 }
void Abort()
Safely stop the current process.

References Abort().

Member Function Documentation

◆ Abort()

void FOOTPRINT_ASYNC_LOADER::Abort ( )

Safely stop the current process.

Definition at line 198 of file footprint_info.cpp.

199 {
200  if( m_list )
201  {
202  m_list->StopWorkers();
203  m_list = nullptr;
204  }
205 }
virtual void StopWorkers()=0
Stop worker threads.
FOOTPRINT_LIST * m_list

References m_list, and FOOTPRINT_LIST::StopWorkers().

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), and ~FOOTPRINT_ASYNC_LOADER().

◆ Join()

bool FOOTPRINT_ASYNC_LOADER::Join ( )

Wait until the worker threads are finished, and then perform any required single-threaded finishing on the list.

This must be called before using the list, even if the completion callback was used!

It is safe to call this method from a thread, but it is not safe to use the list from ANY thread until it completes. It is recommended to call this from the main thread because of this.

It is safe to call this multiple times, but after the first it will always return true.

Returns
true if no errors occurred

Definition at line 185 of file footprint_info.cpp.

186 {
187  if( m_list )
188  {
189  bool rv = m_list->JoinWorkers();
190  m_list = nullptr;
191  return rv;
192  }
193  else
194  return true;
195 }
virtual bool JoinWorkers()=0
Join worker threads.
FOOTPRINT_LIST * m_list

References FOOTPRINT_LIST::JoinWorkers(), and m_list.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ SetList()

void FOOTPRINT_ASYNC_LOADER::SetList ( FOOTPRINT_LIST aList)

Assign a FOOTPRINT_LIST to the loader.

This does not take ownership of the list.

Definition at line 166 of file footprint_info.cpp.

167 {
168  m_list = aList;
169 }
FOOTPRINT_LIST * m_list

References m_list.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ Start()

void FOOTPRINT_ASYNC_LOADER::Start ( FP_LIB_TABLE aTable,
wxString const *  aNickname = nullptr,
unsigned  aNThreads = DEFAULT_THREADS 
)

Launch the worker threads.

Parameters
aTabledefines all the libraries.
aNicknameis the library to read from, or if NULL means read all footprints from all known libraries in aTable.
aNThreadsis the number of worker threads.

Definition at line 172 of file footprint_info.cpp.

174 {
175  // Capture the FP_LIB_TABLE into m_last_table. Formatting it as a string instead of storing the
176  // raw data avoids having to pull in the FP-specific parts.
177  STRING_FORMATTER sof;
178  aTable->Format( &sof, 0 );
179  m_last_table = sof.GetString();
180 
181  m_list->StartWorkers( aTable, aNickname, this, aNThreads );
182 }
FOOTPRINT_LIST * m_list
const std::string & GetString()
Definition: richio.h:475
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:445
virtual void StartWorkers(FP_LIB_TABLE *aTable, wxString const *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads)=0
Launch worker threads to load footprints.

References FP_LIB_TABLE::Format(), STRING_FORMATTER::GetString(), m_last_table, m_list, and FOOTPRINT_LIST::StartWorkers().

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

Friends And Related Function Documentation

◆ FOOTPRINT_LIST

friend class FOOTPRINT_LIST
friend

Definition at line 319 of file footprint_info.h.

◆ FOOTPRINT_LIST_IMPL

friend class FOOTPRINT_LIST_IMPL
friend

Definition at line 320 of file footprint_info.h.

Member Data Documentation

◆ DEFAULT_THREADS

constexpr unsigned FOOTPRINT_ASYNC_LOADER::DEFAULT_THREADS = 6
static

Default number of worker threads.

Determined empirically (by dickelbeck): More than 6 is not significantly faster, less than 6 is likely slower.

Definition at line 376 of file footprint_info.h.

◆ m_last_table

std::string FOOTPRINT_ASYNC_LOADER::m_last_table
private

Definition at line 323 of file footprint_info.h.

Referenced by Start().

◆ m_list

FOOTPRINT_LIST* FOOTPRINT_ASYNC_LOADER::m_list
private

◆ m_total_libs

int FOOTPRINT_ASYNC_LOADER::m_total_libs
private

The documentation for this class was generated from the following files: