timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::operation::async< Tp > Struct Template Reference

#include "timemory/operations/types/async.hpp"

+ Collaboration diagram for tim::operation::async< Tp >:

Public Types

using type = Tp
 
using task_type = std::packaged_task< void()>
 
using this_type = async< Tp >
 
using lock_type = std::unique_lock< std::mutex >
 

Public Member Functions

 async (type &obj)
 
 ~async ()
 
 async (const async &)=delete
 
asyncoperator= (const async &)=delete
 
 async (async &&)=default
 
asyncoperator= (async &&)=default
 
template<typename FuncT , typename... Args>
auto operator() (FuncT &&func, Args... args)
 
void wait ()
 

Detailed Description

template<typename Tp>
struct tim::operation::async< Tp >

Definition at line 41 of file async.hpp.

Member Typedef Documentation

◆ lock_type

template<typename Tp >
using tim::operation::async< Tp >::lock_type = std::unique_lock<std::mutex>

Definition at line 46 of file async.hpp.

◆ task_type

template<typename Tp >
using tim::operation::async< Tp >::task_type = std::packaged_task<void()>

Definition at line 44 of file async.hpp.

◆ this_type

template<typename Tp >
using tim::operation::async< Tp >::this_type = async<Tp>

Definition at line 45 of file async.hpp.

◆ type

template<typename Tp >
using tim::operation::async< Tp >::type = Tp

Definition at line 43 of file async.hpp.

Constructor & Destructor Documentation

◆ async() [1/3]

template<typename Tp >
tim::operation::async< Tp >::async ( type obj)
inlineexplicit

Definition at line 48 of file async.hpp.

49 : m_data{ &obj }
50 , m_thread{ execute_thread, this }
51 {}

◆ ~async()

template<typename Tp >
tim::operation::async< Tp >::~async ( )
inline

Definition at line 53 of file async.hpp.

54 {
55 {
56 m_pool_state.store(false);
57 lock_type _task_lock{ m_task_lock, std::defer_lock };
58 if(!_task_lock.owns_lock())
59 _task_lock.lock();
60 m_task_cond.notify_one();
61 }
62 m_thread.join();
63 }
std::unique_lock< std::mutex > lock_type
Definition: async.hpp:46

◆ async() [2/3]

template<typename Tp >
tim::operation::async< Tp >::async ( const async< Tp > &  )
delete

◆ async() [3/3]

template<typename Tp >
tim::operation::async< Tp >::async ( async< Tp > &&  )
default

Member Function Documentation

◆ operator()()

template<typename Tp >
template<typename FuncT , typename... Args>
auto tim::operation::async< Tp >::operator() ( FuncT &&  func,
Args...  args 
)
inline

Definition at line 72 of file async.hpp.

73 {
74 lock_type _task_lock{ m_task_lock };
75 enqueue(std::forward<FuncT>(func), 0, std::move(args)...);
76 ++m_task_size;
77 m_task_cond.notify_one();
78 }

◆ operator=() [1/2]

template<typename Tp >
async & tim::operation::async< Tp >::operator= ( async< Tp > &&  )
default

◆ operator=() [2/2]

template<typename Tp >
async & tim::operation::async< Tp >::operator= ( const async< Tp > &  )
delete

◆ wait()

template<typename Tp >
void tim::operation::async< Tp >::wait ( )
inline

Definition at line 80 of file async.hpp.

81 {
82 std::deque<std::future<void>> _wait{};
83 {
84 lock_type _task_lock{ m_task_lock, std::defer_lock };
85 std::swap(m_task_wait, _wait);
86 if(!_task_lock.owns_lock())
87 _task_lock.lock();
88 m_task_cond.notify_all();
89 }
90 for(auto& itr : _wait)
91 itr.wait();
92 }

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