Scroom  0.14
ThreadPool::Queue Class Reference

#include <threadpool.hh>

Collaboration diagram for ThreadPool::Queue:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< Queue >
 
using WeakPtr = boost::weak_ptr< Queue >
 

Public Member Functions

 ~Queue ()
 
boost::shared_ptr< Scroom::Detail::ThreadPool::QueueImplget ()
 
boost::shared_ptr< WeakQueuegetWeak ()
 

Static Public Member Functions

static Ptr create ()
 ThreadPool::Queue. More...
 
static Ptr createAsync ()
 

Private Member Functions

 Queue ()
 
 Queue (const Queue &)=delete
 
 Queue (Queue &&)=delete
 
Queueoperator= (const Queue &)=delete
 
Queueoperator= (Queue &&)=delete
 

Private Attributes

boost::shared_ptr< WeakQueueweak
 

Detailed Description

Represent a Queue in the ThreadPool.

If pass in a Queue object when you schedule() your job, then your job will be scheduled on that particular queue. This does not in any way affect the order in which jobs are executed. Use priority for that. Instead, if you later delete your Queue, any jobs scheduled on that Queue will not be executed any more.

When you delete the Queue, your thread will block until any jobs currently being executed have finished. I.e. after the Queue is destroyed, no jobs will be running any more, nor will any be run in the future. This can cause deadlocks if a job running on a ThreadPool tries to destroy its own queue.

To avoid deadlock, you should make sure that jobs running on the ThreadPool only have references to WeakQueue objects, or you should create your Queue using createAsync(). This will do the actual Queue destruction on a separate thread. As a result, after the last reference to the Queue object goes out of scope, jobs on the Queue may continue running for some time.

Note
If you delete the Queue, the associated jobs will not actually be deleted. Instead, when the time comes to execute the job, a check is done whether the Queue still exists. If it doesn't, the job is silently discarded.

Member Typedef Documentation

◆ Ptr

using ThreadPool::Queue::Ptr = boost::shared_ptr<Queue>

◆ WeakPtr

using ThreadPool::Queue::WeakPtr = boost::weak_ptr<Queue>

Constructor & Destructor Documentation

◆ ~Queue()

ThreadPool::Queue::~Queue ( )
386 { weak->get()->deletingQueue(); }

◆ Queue() [1/3]

ThreadPool::Queue::Queue ( )
private
383 {
384 }

◆ Queue() [2/3]

ThreadPool::Queue::Queue ( const Queue )
privatedelete

◆ Queue() [3/3]

ThreadPool::Queue::Queue ( Queue &&  )
privatedelete

Member Function Documentation

◆ create()

ThreadPool::Queue::Ptr ThreadPool::Queue::create ( )
static

ThreadPool::Queue.

When the last reference goes out of scope, synchronously destroy the Queue, blocking until any currently running jobs are finished.

377 { return ThreadPool::Queue::Ptr(new ThreadPool::Queue()); }

Referenced by BOOST_AUTO_TEST_CASE(), ThreadPool::defaultQueue(), and CompressedTile::observerAdded().

Here is the caller graph for this function:

◆ createAsync()

ThreadPool::Queue::Ptr ThreadPool::Queue::createAsync ( )
static

When the last reference goes out of scope, asynchronously destroy the Queue. Jobs scheduled on the Queue may continue running for some time.

Referenced by TileViewState::kick(), and Scroom::TiledBitmap::scheduleLoadingBitmap().

Here is the caller graph for this function:

◆ get()

QueueImpl::Ptr ThreadPool::Queue::get ( )
388 { return weak->get(); }

◆ getWeak()

ThreadPool::WeakQueue::Ptr ThreadPool::Queue::getWeak ( )
390 { return weak; }

◆ operator=() [1/2]

Queue& ThreadPool::Queue::operator= ( const Queue )
privatedelete

◆ operator=() [2/2]

Queue& ThreadPool::Queue::operator= ( Queue &&  )
privatedelete

Member Data Documentation

◆ weak

boost::shared_ptr<WeakQueue> ThreadPool::Queue::weak
private

The documentation for this class was generated from the following files:
ThreadPool::Queue::Ptr
boost::shared_ptr< Queue > Ptr
Definition: threadpool.hh:82
AsyncDeleter
Definition: async-deleter.hh:41
ThreadPool::Queue
Definition: threadpool.hh:79
ThreadPool::Queue::weak
boost::shared_ptr< WeakQueue > weak
Definition: threadpool.hh:112
ThreadPool::WeakQueue::create
static Ptr create()
ThreadPool::WeakQueue.
Definition: threadpoolimpl.cc:396