vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
vitrio::counting_completion Class Referencefinal

A completion that resolves once a fixed number of units of work have all reported in. More...

#include <vitrio/concurrency/counting_completion.hpp>

Inheritance diagram for vitrio::counting_completion:
Inheritance graph
[legend]
Collaboration diagram for vitrio::counting_completion:
Collaboration graph
[legend]

Public Member Functions

 counting_completion (std::size_t count)
 Construct a completion for a known number of units of work.
 
 counting_completion (const counting_completion &other)=delete
 
 counting_completion (counting_completion &&other)=delete
 
counting_completion & operator= (const counting_completion &other)=delete
 
counting_completion & operator= (counting_completion &&other)=delete
 
void notify_done (std::exception_ptr error=nullptr) override
 Report that one unit of work has finished.
 
void wait () const override
 Block the calling thread until this is ready.
 
bool is_ready () const noexcept override
 Whether the work behind this has finished.
 
void get () const override
 Wait, then rethrow the first exception recorded, if any.
 
- Public Member Functions inherited from vitrio::completion
 completion (const completion &other)=default
 
 completion (completion &&other)=default
 
completion & operator= (const completion &other)=default
 
completion & operator= (completion &&other)=default
 
- Public Member Functions inherited from vitrio::completion_notifier
 completion_notifier (const completion_notifier &other)=default
 
 completion_notifier (completion_notifier &&other)=default
 
completion_notifier & operator= (const completion_notifier &other)=default
 
completion_notifier & operator= (completion_notifier &&other)=default
 

Detailed Description

A completion that resolves once a fixed number of units of work have all reported in.

A semaphore-style countdown from a starting count to zero, not a counter compared against a separately kept target. Resolves only once every unit of work has reported, regardless of which ones failed or when, so a caller of completion::wait never observes this ready while another unit of work behind it is still running. The first exception reported, if any, is what get rethrows; the rest are discarded.

Implements both completion and completion_notifier so that the same object serves both audiences, each reached through the interface meant for it: the query side goes to whoever asked for the work, the notifying side goes to the executor running it.

Thread safety
notify_done may be called concurrently, from as many threads as the starting count.

Constructor & Destructor Documentation

◆ counting_completion()

vitrio::counting_completion::counting_completion ( std::size_t  count)
explicit

Construct a completion for a known number of units of work.

A count of zero constructs a completion that is already resolved.

Parameters
countHow many times notify_done is reported before this resolves.

Member Function Documentation

◆ get()

void vitrio::counting_completion::get ( ) const
overridevirtual

Wait, then rethrow the first exception recorded, if any.

Exceptions
Whateverthe first unit of work to fail threw.

Implements vitrio::completion.

◆ is_ready()

bool vitrio::counting_completion::is_ready ( ) const
overridevirtualnoexcept

Whether the work behind this has finished.

Returns
bool True once every unit of work this stands for has run, successfully or not.

Implements vitrio::completion.

◆ notify_done()

void vitrio::counting_completion::notify_done ( std::exception_ptr  error = nullptr)
overridevirtual

Report that one unit of work has finished.

Called exactly once per unit of work this notifier stands for.

Parameters
errorThe exception the unit of work raised, or null if it succeeded.
Thread safety
May be called concurrently, from as many threads as there are units of work.

Implements vitrio::completion_notifier.

◆ wait()

void vitrio::counting_completion::wait ( ) const
overridevirtual

Block the calling thread until this is ready.

Implements vitrio::completion.


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