KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DB_PROBE_LATCH< T > Class Template Reference

Runs a slow probe once on a thread of its own and keeps its answer for good. More...

#include <db_backend_support.h>

Public Member Functions

 DB_PROBE_LATCH (std::function< T()> aProbe)
 
std::optional< T > Get (std::chrono::milliseconds aWait)
 The probe's answer, or nothing if it has not finished within aWait. A probe that throws answers T().
 

Private Attributes

std::function< T()> m_probe
 
std::once_flag m_started
 
std::shared_future< T > m_answer
 

Detailed Description

template<typename T>
class DB_PROBE_LATCH< T >

Runs a slow probe once on a thread of its own and keeps its answer for good.

Only a finished answer is kept. A caller that gives up waiting gets nothing, and the next caller waits on the same probe, so contention that delays the probe is never taken for a negative result.

Definition at line 128 of file db_backend_support.h.

Constructor & Destructor Documentation

◆ DB_PROBE_LATCH()

template<typename T>
DB_PROBE_LATCH< T >::DB_PROBE_LATCH ( std::function< T()> aProbe)
inlineexplicit

Definition at line 131 of file db_backend_support.h.

References m_probe, and move.

Member Function Documentation

◆ Get()

template<typename T>
std::optional< T > DB_PROBE_LATCH< T >::Get ( std::chrono::milliseconds aWait)
inline

The probe's answer, or nothing if it has not finished within aWait. A probe that throws answers T().

Definition at line 137 of file db_backend_support.h.

References m_answer, m_probe, m_started, and T.

Member Data Documentation

◆ m_answer

template<typename T>
std::shared_future<T> DB_PROBE_LATCH< T >::m_answer
private

Definition at line 172 of file db_backend_support.h.

Referenced by Get().

◆ m_probe

template<typename T>
std::function<T()> DB_PROBE_LATCH< T >::m_probe
private

Definition at line 170 of file db_backend_support.h.

Referenced by DB_PROBE_LATCH(), and Get().

◆ m_started

template<typename T>
std::once_flag DB_PROBE_LATCH< T >::m_started
private

Definition at line 171 of file db_backend_support.h.

Referenced by Get().


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