#include "RunQueue.hpp" RunQueue::RunQueue() : m_mainThread( std::this_thread::get_id() ) { } void RunQueue::Queue( std::function cb, bool forceDelay ) { if( !forceDelay && std::this_thread::get_id() == m_mainThread ) { cb(); } else { std::lock_guard lock( m_lock ); m_queue.emplace_back( cb ); } } void RunQueue::Run() { std::unique_lock lock( m_lock ); if( !m_queue.empty() ) { std::vector> tmp; std::swap( tmp, m_queue ); lock.unlock(); for( auto& cb : tmp ) cb(); } }