A library for working with phylogenetic and population genetic data.
v0.32.0
AsynchronousReader Class Reference

#include <genesis/utils/io/input_reader.hpp>

Detailed Description

Read bytes from an InputSource into a char buffer.

The reading is done asynchronously, that is, in another thread. This is usually faster than synchronous reading (see SynchronousReader), particularly for large data blocks, because we can avoid blocking any computational threads for I/O wait times. It is thus the preferred reader, if available.

In detail, if we have a trival input source, such as just reading data from a file, it get its own thread pool with one thread, which boils down to just a thread and condition variable for notifying the thread, and hence is a realative lightweight way of not blocking any computational threads with I/O wait times. For more complex inputs, such as gzip that needs decompression, and hence is not a trivial I/O wait, we instead use a given or the global thread pool, to avoid oversubscribing our desired thread count, and spamming too many async reader threads when multiple files need to be processed at the same time.

The caller is responsible for keeping the data buffer alive while the reading is happening. That is, calling start_reading() without then also calling finish_reading() and having the buffer go out of scope could lead to a segfault. Don't do that. Also, each call to start_reading() needs to be matched by a call to finish_reading() before calling start_reading() again, as otherwise, the input data will get scrambled.

Implementation details inspired by fast-cpp-csv-parser by Ben Strasser, see also Acknowledgements.

Definition at line 93 of file input_reader.hpp.

Public Member Functions

 AsynchronousReader (AsynchronousReader &&)=delete
 
 AsynchronousReader (AsynchronousReader const &)=delete
 
 AsynchronousReader (std::shared_ptr< BaseInputSource > input_source, std::shared_ptr< ThreadPool > thread_pool=nullptr)
 
 ~AsynchronousReader ()=default
 
std::string class_name () const
 
size_t finish_reading ()
 
std::shared_ptr< BaseInputSourceinput_source () const
 
AsynchronousReaderoperator= (AsynchronousReader &&)=delete
 
AsynchronousReaderoperator= (AsynchronousReader const &)=delete
 
void start_reading (char *target_buffer, size_t target_size)
 
bool valid () const
 

Constructor & Destructor Documentation

◆ AsynchronousReader() [1/3]

AsynchronousReader ( std::shared_ptr< BaseInputSource input_source,
std::shared_ptr< ThreadPool thread_pool = nullptr 
)
inline

Definition at line 101 of file input_reader.hpp.

◆ AsynchronousReader() [2/3]

AsynchronousReader ( AsynchronousReader const &  )
delete

◆ AsynchronousReader() [3/3]

◆ ~AsynchronousReader()

~AsynchronousReader ( )
default

Member Function Documentation

◆ class_name()

std::string class_name ( ) const
inline

Definition at line 177 of file input_reader.hpp.

◆ finish_reading()

size_t finish_reading ( )
inline

Definition at line 209 of file input_reader.hpp.

◆ input_source()

std::shared_ptr<BaseInputSource> input_source ( ) const
inline

Definition at line 172 of file input_reader.hpp.

◆ operator=() [1/2]

AsynchronousReader& operator= ( AsynchronousReader &&  )
delete

◆ operator=() [2/2]

AsynchronousReader& operator= ( AsynchronousReader const &  )
delete

◆ start_reading()

void start_reading ( char *  target_buffer,
size_t  target_size 
)
inline

Definition at line 186 of file input_reader.hpp.

◆ valid()

bool valid ( ) const
inline

Definition at line 167 of file input_reader.hpp.


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