AVIR
High-quality pro image resizing library
 All Classes Files Functions Variables Typedefs Macros
Classes | Public Member Functions | List of all members
avir::CImageResizerThreadPool Class Reference

#include <avir.h>

Classes

class  CWorkload
 

Public Member Functions

virtual void addWorkload (CWorkload *const Workload)
 
virtual int getSuggestedWorkloadCount () const
 
virtual void removeAllWorkloads ()
 
virtual void startAllWorkloads ()
 
virtual void waitAllWorkloadsToFinish ()
 

Detailed Description

Thread pool for multi-threaded image resizing operation.

This base class is used to organize a multi-threaded image resizing operation. The thread pool should consist of threads that initially wait for a signal. Upon receiving a signal (via the startAllWorkloads() function) each previously added thread should execute its workload's process() function once, and return to the wait signal state again. The thread pool should be also able to efficiently wait for all workloads to finish via the waitAllWorkloadsToFinish() function.

The image resizing algorithm makes calls to functions of this class.

Member Function Documentation

virtual void avir::CImageResizerThreadPool::addWorkload ( CWorkload *const  Workload)
virtual

Function adds a new workload (and possibly thread) to the thread pool. The caller decides how many parallel workloads (and threads) it requires, but this number will not exceed the value returned by the getSuggestedWorkloadCount() function. It is implementation-specific how many workloads to associate with a single thread. But for efficiency reasons each workload should be associated with its own thread.

Note that the same set of workload objects will be processed each time the startAllWorkloads() function is called. This means that workload objects are added only once. The caller changes the state of the workload objects and then calls the startAllWorkloads() function to process them.

Parameters
WorkloadWorkload object whose process() function will be called from within the thread when the startAllWorkloads() function is called.
virtual int avir::CImageResizerThreadPool::getSuggestedWorkloadCount ( ) const
virtual
Returns
The suggested number of workloads (and their associated threads) to add. The minimal value this function can return is 1. The usual value may depend on the number of physical and virtual cores present in the system, and on other considerations.
virtual void avir::CImageResizerThreadPool::removeAllWorkloads ( )
virtual

Function removes all workloads previously added via the addWorkload() function. This function gets called only after the waitAllWorkloadsToFinish() function call.

virtual void avir::CImageResizerThreadPool::startAllWorkloads ( )
virtual

Function starts all workloads associated with threads previously added via the addWorkload() function. It is assumed that this function performs the necessary "memory barrier" (or "cache sync") kind of operation so that all threads catch up the prior changes made to the workload objects during their wait state.

virtual void avir::CImageResizerThreadPool::waitAllWorkloadsToFinish ( )
virtual

Function waits for all workloads to finish.