AVIR
High-quality pro image resizing library
 
Loading...
Searching...
No Matches
avir::CImageResizerThreadPool Class Reference

Thread pool for multi-threaded image resizing operation. More...

#include <avir.h>

Classes

class  CWorkload
 Thread pool's workload object class. More...
 

Public Member Functions

virtual void addWorkload (CWorkload *const Workload)
 Adds a new workload (and possibly thread) to the thread pool.
 
virtual int getSuggestedWorkloadCount () const
 Returns the suggested number of workloads (and their associated threads) to add.
 
virtual void removeAllWorkloads ()
 Removes all workloads previously added via the addWorkload() function.
 
virtual void startAllWorkloads ()
 Starts all workloads associated with threads previously added via the addWorkload() function.
 
virtual void waitAllWorkloadsToFinish ()
 Waits for all workloads to finish.
 

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

◆ addWorkload()

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

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 to the thread pool only once. The caller changes the state of the workload objects, and then calls the startAllWorkloads() function to process them all.

Parameters
WorkloadWorkload object whose process() function will be called from within the thread, when the startAllWorkloads() function is called.

◆ getSuggestedWorkloadCount()

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.

Returns
Suggested number of workloads.

◆ removeAllWorkloads()

virtual void avir::CImageResizerThreadPool::removeAllWorkloads ( )
virtual

Removes all workloads previously added via the addWorkload() function.

This function gets called only after the waitAllWorkloadsToFinish() function call.

◆ startAllWorkloads()

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

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.