KiCad PCB EDA Suite
FOOTPRINT_ASYNC_LOADER Class Reference

Object 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, const wxString *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...
 

Private Attributes

FOOTPRINT_LISTm_list
 
std::string m_last_table
 
int m_total_libs
 

Static Private Attributes

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

Friends

class FOOTPRINT_LIST
 
class FOOTPRINT_LIST_IMPL
 

Detailed Description

Object used to populate a FOOTPRINT_LIST asynchronously.

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

Definition at line 306 of file footprint_info.h.

Constructor & Destructor Documentation

◆ FOOTPRINT_ASYNC_LOADER()

FOOTPRINT_ASYNC_LOADER::FOOTPRINT_ASYNC_LOADER ( )

Construct an asynchronous loader.

Definition at line 157 of file footprint_info.cpp.

157  : m_list( nullptr )
158 {
159  m_total_libs = 0;
160 }
FOOTPRINT_LIST * m_list

References m_total_libs.

◆ ~FOOTPRINT_ASYNC_LOADER()

FOOTPRINT_ASYNC_LOADER::~FOOTPRINT_ASYNC_LOADER ( )

Definition at line 163 of file footprint_info.cpp.

164 {
165  // This is NOP if the load has finished
166  Abort();
167 }
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 205 of file footprint_info.cpp.

206 {
207  if( m_list )
208  {
209  m_list->stopWorkers();
210  m_list = nullptr;
211  }
212 
213  KIID::CreateNilUuids( false );
214 }
virtual void stopWorkers()=0
Stop worker threads.
FOOTPRINT_LIST * m_list
static void CreateNilUuids(bool aNil=true)
Definition: kiid.cpp:240

References KIID::CreateNilUuids(), 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 192 of file footprint_info.cpp.

193 {
194  if( m_list )
195  {
196  bool rv = m_list->joinWorkers();
197  m_list = nullptr;
198  return rv;
199  }
200  else
201  return true;
202 }
FOOTPRINT_LIST * m_list
virtual bool joinWorkers()=0
Join worker threads.

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 170 of file footprint_info.cpp.

171 {
172  m_list = aList;
173 }
FOOTPRINT_LIST * m_list

References m_list.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ Start()

void FOOTPRINT_ASYNC_LOADER::Start ( FP_LIB_TABLE aTable,
const wxString *  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 176 of file footprint_info.cpp.

178 {
179  // Disable KIID generation: not needed for library parts; sometimes very slow
180  KIID::CreateNilUuids( true );
181 
182  // Capture the FP_LIB_TABLE into m_last_table. Formatting it as a string instead of storing the
183  // raw data avoids having to pull in the FP-specific parts.
184  STRING_FORMATTER sof;
185  aTable->Format( &sof, 0 );
186  m_last_table = sof.GetString();
187 
188  m_list->startWorkers( aTable, aNickname, this, aNThreads );
189 }
FOOTPRINT_LIST * m_list
const std::string & GetString()
Definition: richio.h:438
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
static void CreateNilUuids(bool aNil=true)
Definition: kiid.cpp:240
virtual void startWorkers(FP_LIB_TABLE *aTable, const wxString *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads)=0
Launch worker threads to load footprints.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414

References KIID::CreateNilUuids(), 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 361 of file footprint_info.h.

◆ FOOTPRINT_LIST_IMPL

friend class FOOTPRINT_LIST_IMPL
friend

Definition at line 362 of file footprint_info.h.

Member Data Documentation

◆ DEFAULT_THREADS

constexpr unsigned FOOTPRINT_ASYNC_LOADER::DEFAULT_THREADS = 6
staticprivate

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 359 of file footprint_info.h.

◆ m_last_table

std::string FOOTPRINT_ASYNC_LOADER::m_last_table
private

Definition at line 365 of file footprint_info.h.

Referenced by Start().

◆ m_list

FOOTPRINT_LIST* FOOTPRINT_ASYNC_LOADER::m_list
private

Definition at line 364 of file footprint_info.h.

Referenced by Abort(), Join(), SetList(), and Start().

◆ m_total_libs

int FOOTPRINT_ASYNC_LOADER::m_total_libs
private

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