KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGFX::FRAME_MAILBOX Class Reference

Lock-free single-slot mailbox carrying frame state from the main thread to the render thread. More...

#include <frame_mailbox.h>

Public Member Functions

 FRAME_MAILBOX ()=default
 
 ~FRAME_MAILBOX ()
 
 FRAME_MAILBOX (const FRAME_MAILBOX &)=delete
 
FRAME_MAILBOX & operator= (const FRAME_MAILBOX &)=delete
 
std::unique_ptr< FRAME_PACKET > Submit (std::unique_ptr< FRAME_PACKET > aPacket)
 
std::unique_ptr< FRAME_PACKET > Load ()
 
uint64_t ConsumedBufferGeneration () const
 
uint64_t PendingInputSerial () const
 

Private Attributes

std::atomic< FRAME_PACKET * > m_pending { nullptr }
 
std::atomic< uint64_t > m_consumedGeneration { 0 }
 
std::atomic< uint64_t > m_pendingInputSerial { 0 }
 

Detailed Description

Lock-free single-slot mailbox carrying frame state from the main thread to the render thread.

Only the latest packet is kept, so the render thread never draws a stale frame. One producer and one consumer may call Submit() and Load() concurrently.

Definition at line 38 of file frame_mailbox.h.

Constructor & Destructor Documentation

◆ FRAME_MAILBOX() [1/2]

KIGFX::FRAME_MAILBOX::FRAME_MAILBOX ( )
default

Referenced by FRAME_MAILBOX(), and operator=().

◆ ~FRAME_MAILBOX()

KIGFX::FRAME_MAILBOX::~FRAME_MAILBOX ( )
inline

Definition at line 43 of file frame_mailbox.h.

References m_pending.

◆ FRAME_MAILBOX() [2/2]

KIGFX::FRAME_MAILBOX::FRAME_MAILBOX ( const FRAME_MAILBOX & )
delete

References FRAME_MAILBOX().

Member Function Documentation

◆ ConsumedBufferGeneration()

uint64_t KIGFX::FRAME_MAILBOX::ConsumedBufferGeneration ( ) const
inline
Returns
the buffer generation of the packet the consumer loaded last. The producer may free whatever it retired at or before that generation.

Definition at line 87 of file frame_mailbox.h.

References m_consumedGeneration.

◆ Load()

std::unique_ptr< FRAME_PACKET > KIGFX::FRAME_MAILBOX::Load ( )
inline
Returns
the pending packet, or nullptr if nothing was submitted since the last Load().

Older packets are never drawn again, so their retired buffers can be freed.

Definition at line 72 of file frame_mailbox.h.

References m_consumedGeneration, and m_pending.

Referenced by KIGFX::RENDER_THREAD::ProcessActiveWindows().

◆ operator=()

FRAME_MAILBOX & KIGFX::FRAME_MAILBOX::operator= ( const FRAME_MAILBOX & )
delete

References FRAME_MAILBOX().

◆ PendingInputSerial()

uint64_t KIGFX::FRAME_MAILBOX::PendingInputSerial ( ) const
inline
Returns
the input serial of the newest packet submitted.

Definition at line 95 of file frame_mailbox.h.

References m_pendingInputSerial.

Referenced by KIGFX::RENDER_THREAD::ProcessActiveWindows().

◆ Submit()

std::unique_ptr< FRAME_PACKET > KIGFX::FRAME_MAILBOX::Submit ( std::unique_ptr< FRAME_PACKET > aPacket)
inline
Returns
the displaced unread packet, or nullptr if the consumer already took it.

Definition at line 54 of file frame_mailbox.h.

References m_pending, and m_pendingInputSerial.

Member Data Documentation

◆ m_consumedGeneration

std::atomic<uint64_t> KIGFX::FRAME_MAILBOX::m_consumedGeneration { 0 }
private

Definition at line 102 of file frame_mailbox.h.

Referenced by ConsumedBufferGeneration(), and Load().

◆ m_pending

std::atomic<FRAME_PACKET*> KIGFX::FRAME_MAILBOX::m_pending { nullptr }
private

Definition at line 101 of file frame_mailbox.h.

Referenced by Load(), Submit(), and ~FRAME_MAILBOX().

◆ m_pendingInputSerial

std::atomic<uint64_t> KIGFX::FRAME_MAILBOX::m_pendingInputSerial { 0 }
private

Definition at line 103 of file frame_mailbox.h.

Referenced by PendingInputSerial(), and Submit().


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