rippled
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::io_list Class Referencefinal

Manages a set of objects performing asynchronous I/O. More...

#include <io_list.h>

Collaboration diagram for ripple::io_list:
Collaboration graph
[legend]

Classes

class  work
 

Public Member Functions

 io_list ()=default
 
 ~io_list ()
 Destroy the list.
 
bool closed () const
 Return true if the list is closed.
 
template<class T , class... Args>
std::shared_ptr< T > emplace (Args &&... args)
 Create associated work if not closed.
 
template<class Finisher >
void close (Finisher &&f)
 Cancel active I/O.
 
void close ()
 
template<class = void>
void join ()
 Block until the io_list stops.
 

Private Member Functions

template<class = void>
void destroy ()
 

Private Attributes

std::mutex m_
 
std::size_t n_ = 0
 
bool closed_ = false
 
std::condition_variable cv_
 
boost::container::flat_map< work *, std::weak_ptr< work > > map_
 
std::function< void(void)> f_
 

Detailed Description

Manages a set of objects performing asynchronous I/O.

Definition at line 16 of file io_list.h.

Constructor & Destructor Documentation

◆ io_list()

ripple::io_list::io_list ( )
default

◆ ~io_list()

ripple::io_list::~io_list ( )

Destroy the list.

Effects: Closes the io_list if it was not previously closed. No finisher is invoked in this case.

Blocks until all work is destroyed.

Definition at line 73 of file io_list.h.

Member Function Documentation

◆ destroy()

template<class >
void ripple::io_list::destroy ( )
private

Definition at line 183 of file io_list.h.

◆ closed()

bool ripple::io_list::closed ( ) const

Return true if the list is closed.

Thread Safety: Undefined result if called concurrently with close().

Definition at line 85 of file io_list.h.

◆ emplace()

template<class T , class... Args>
std::shared_ptr< T > ripple::io_list::emplace ( Args &&...  args)

Create associated work if not closed.

Requirements: std::is_base_of_v<work, T> == true

Thread Safety: May be called concurrently.

Effects: Atomically creates, inserts, and returns new work T, or returns nullptr if the io_list is closed,

If the call succeeds and returns a new object, it is guaranteed that a subsequent call to close will invoke work::close on the object.

Definition at line 191 of file io_list.h.

◆ close() [1/2]

template<class Finisher >
void ripple::io_list::close ( Finisher &&  f)

Cancel active I/O.

Thread Safety: May not be called concurrently.

Effects: Associated work is closed.

Finisher if provided, will be called when all associated work is destroyed. The finisher may be called from a foreign thread, or within the call to this function.

Only the first call to close will set the finisher.

No effect after the first call.

Definition at line 216 of file io_list.h.

◆ close() [2/2]

void ripple::io_list::close ( )

Definition at line 135 of file io_list.h.

◆ join()

template<class >
void ripple::io_list::join ( )

Block until the io_list stops.

Effects: The caller is blocked until the io_list is closed and all associated work is destroyed.

Thread safety: May be called concurrently.

Preconditions: No call to io_context::run on any io_context used by work objects associated with this io_list exists in the caller's call stack.

Definition at line 240 of file io_list.h.

Member Data Documentation

◆ m_

std::mutex ripple::io_list::m_
private

Definition at line 55 of file io_list.h.

◆ n_

std::size_t ripple::io_list::n_ = 0
private

Definition at line 56 of file io_list.h.

◆ closed_

bool ripple::io_list::closed_ = false
private

Definition at line 57 of file io_list.h.

◆ cv_

std::condition_variable ripple::io_list::cv_
private

Definition at line 58 of file io_list.h.

◆ map_

boost::container::flat_map<work*, std::weak_ptr<work> > ripple::io_list::map_
private

Definition at line 59 of file io_list.h.

◆ f_

std::function<void(void)> ripple::io_list::f_
private

Definition at line 60 of file io_list.h.