|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_IO_INPUT_READER_H_
2 #define GENESIS_UTILS_IO_INPUT_READER_H_
51 class AsynchronousReader;
52 class SynchronousReader;
103 std::shared_ptr<ThreadPool> thread_pool =
nullptr
106 throw std::runtime_error(
"Cannot read from BaseInputSource nullptr" );
114 auto get_thread_pool_ = [&]()
134 switch(
Options::get().input_reading_thread_policy() ) {
136 thread_pool_ = get_thread_pool_();
141 thread_pool_ = std::make_shared<utils::ThreadPool>( 1 );
143 thread_pool_ = get_thread_pool_();
148 thread_pool_ = std::make_shared<utils::ThreadPool>( 1 );
169 return input_source_ !=
nullptr;
174 return input_source_;
179 return "AsynchronousReader";
190 assert( target_buffer );
194 assert( ! future_.
valid() );
202 future_ = thread_pool_->enqueue_and_retrieve(
204 return input_source->read( target_buffer, target_size );
212 assert( future_.
valid() );
217 return future_.
get();
227 std::shared_ptr<BaseInputSource> input_source_;
230 std::shared_ptr<ThreadPool> thread_pool_;
280 return input_source_ !=
nullptr;
285 return input_source_;
290 return "SynchronousReader";
299 target_buffer_ = target_buffer;
300 target_size_ = target_size;
305 return input_source_->read( target_buffer_, target_size_ );
314 std::shared_ptr<BaseInputSource> input_source_;
316 char* target_buffer_;
323 #endif // include guard
std::shared_ptr< BaseInputSource > input_source() const
Read bytes from an InputSource into a char buffer.
std::shared_ptr< ThreadPool > global_thread_pool() const
Return a global thread pool to be used for parallel computations.
std::string class_name() const
T get()
Return the result, after calling wait().
void start_reading(char *target_buffer, size_t target_size)
std::shared_ptr< BaseInputSource > input_source() const
AsynchronousReader & operator=(AsynchronousReader const &)=delete
std::string class_name() const
void start_reading(char *target_buffer, size_t target_size)
Read bytes from an InputSource into a char buffer.
SynchronousReader & operator=(SynchronousReader const &)=delete
SynchronousReader(std::shared_ptr< BaseInputSource > input_source)
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
~SynchronousReader()=default
@ kAllAsync
All reading from input sources gets their own thread.
AsynchronousReader(std::shared_ptr< BaseInputSource > input_source, std::shared_ptr< ThreadPool > thread_pool=nullptr)
@ kTrivialAsync
Use async threads for trivial input sources, such as simple files, but use the global thread pool for...
@ kStrict
All input reading uses the global thread pool.
bool valid() const noexcept
Check if the future has a shared state.
static Options & get()
Returns a single instance of this class.
~AsynchronousReader()=default