Regina 7.0 Calculation Engine
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
regina::ProgressTrackerBase Class Reference

The base class for Regina's progress tracking classes. More...

#include <progress/progresstracker.h>

Inheritance diagram for regina::ProgressTrackerBase:
regina::ProgressTracker regina::ProgressTrackerOpen

Public Member Functions

bool isFinished () const
 Queries whether the writing thread has finished all processing. More...
 
bool descriptionChanged () const
 Queries whether the stage description has changed since the last call to descriptionChanged(). More...
 
std::string description () const
 Returns the human-readable description of the current stage. More...
 
void cancel ()
 Indicates to the writing thread that the user wishes to cancel the operation. More...
 
bool isCancelled () const
 Queries whether the reading thread has made a request for the writing thread to cancel the operation; in other words, whether cancel() has been called. More...
 
void setFinished ()
 Used by the writing thread to indicate that it has finished all processing. More...
 
 ProgressTrackerBase (const ProgressTrackerBase &)=delete
 
ProgressTrackerBaseoperator= (const ProgressTrackerBase &)=delete
 

Protected Member Functions

 ProgressTrackerBase ()
 Creates a new progress tracker. More...
 

Protected Attributes

std::string desc_
 The human-readable description of the current stage. More...
 
bool descChanged_
 Has the description changed since the last call to descriptionChanged()? More...
 
bool cancelled_
 Has the reading thread requested that the operation be cancelled? More...
 
bool finished_
 Has the writing thread declared that it has finished all processing? More...
 
std::mutex lock_
 A mutex to stop the reading and writing threads from interfering with each other. More...
 

Detailed Description

The base class for Regina's progress tracking classes.

These classes manage progress tracking and cancellation polling for long operations. A typical progress tracker is simultaneously used by a writing thread, which is performing the long calculations, and a reading thread, which displays progress updates to the user and/or takes cancellation requests from the user.

Progress works through a series of stages. Each stage has a text description, as well as a numerical progress indicator. For the class ProgressTracker, this is a percentage that rises from 0 to 100 as the stage progresses; for ProgressTrackerOpen, this is an integer that starts at 0 and rises (with no particular upper bound).

The life cycle of a progress tracker is as follows.

It is imperative that the writing thread does not access the tracker after calling setFinished(), and it is imperative that the reading thread does not destroy the tracker until after isFinished() returns true. In particular, even if the reading thread has called cancel(), it must still wait upon isFinished() before destroying the tracker. Until isFinished() returns true, there is no guarantee that the writing thread has detected and honoured the cancellation request.

Progress trackers rely on multiple threads accessing the same underlying object, and so they cannot be copied, moved or swapped.

Note
This class implements common functionality for ProgressTracker and ProgressTrackerOpen, and should not be used on its own. Instead, you should always use either ProgressTracker or ProgressTrackerOpen (according to whether you need percentage-based or open-ended progress tracking respectively).

Constructor & Destructor Documentation

◆ ProgressTrackerBase()

regina::ProgressTrackerBase::ProgressTrackerBase ( )
inlineprotected

Creates a new progress tracker.

This sets a sensible state description (which declares that the operation is initialising).

This is only ever called by subclass constructors.

Member Function Documentation

◆ cancel()

void regina::ProgressTrackerBase::cancel ( )
inline

Indicates to the writing thread that the user wishes to cancel the operation.

The writing thread might not detect and/or respond to this request immediately (or indeed ever), and so the reading thread should continue to wait until isFinished() returns true before it cleans up and destroys this progress tracker.

This is typically called by the reading thread.

◆ description()

std::string regina::ProgressTrackerBase::description ( ) const
inline

Returns the human-readable description of the current stage.

This is typically called by the reading thread.

Returns
the current stage description.

◆ descriptionChanged()

bool regina::ProgressTrackerBase::descriptionChanged ( ) const
inline

Queries whether the stage description has changed since the last call to descriptionChanged().

If this is the first time descriptionChanged() is called, the result will be true.

This is typically called by the reading thread.

Returns
true if and only if the stage description has changed.

◆ isCancelled()

bool regina::ProgressTrackerBase::isCancelled ( ) const
inline

Queries whether the reading thread has made a request for the writing thread to cancel the operation; in other words, whether cancel() has been called.

This is typically called by the writing thread.

Returns
true if and only if a cancellation request has been made.

◆ isFinished()

bool regina::ProgressTrackerBase::isFinished ( ) const
inline

Queries whether the writing thread has finished all processing.

This will eventually return true regardless of whether the processing finished naturally or was cancelled by the reading thread.

This is typically called by the reading thread.

Returns
true if and only if the writing thread has finished all processing.

◆ setFinished()

void regina::ProgressTrackerBase::setFinished ( )

Used by the writing thread to indicate that it has finished all processing.

The stage description will be updated to indicate that the operation is finished.

This is typically called by the writing thread.

Warning
The base class implementation of this routine should never be called (and indeed, it is declared here but not implemented). You should always call either ProgressTracker::setFinished() or ProgressTrackerOpen::setFinished().

Member Data Documentation

◆ cancelled_

bool regina::ProgressTrackerBase::cancelled_
protected

Has the reading thread requested that the operation be cancelled?

◆ desc_

std::string regina::ProgressTrackerBase::desc_
protected

The human-readable description of the current stage.

◆ descChanged_

bool regina::ProgressTrackerBase::descChanged_
protected

Has the description changed since the last call to descriptionChanged()?

◆ finished_

bool regina::ProgressTrackerBase::finished_
protected

Has the writing thread declared that it has finished all processing?

◆ lock_

std::mutex regina::ProgressTrackerBase::lock_
mutableprotected

A mutex to stop the reading and writing threads from interfering with each other.


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

Copyright © 1999-2021, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).