Scroom  0.14
threadpool.hh File Reference
#include <queue>
#include <vector>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <scroom/semaphore.hh>
#include <scroom/impl/threadpoolimpl.hh>
Include dependency graph for threadpool.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ThreadPool
 
class  ThreadPool::Queue
 
class  ThreadPool::WeakQueue
 
struct  ThreadPool::Job
 
class  ThreadPool::PrivateData
 
class  QueueJumper
 

Namespaces

 Scroom
 
 Scroom::Detail
 
 Scroom::Detail::ThreadPool
 

Enumerations

enum  {
  PRIO_HIGHEST = 100, PRIO_HIGHER, PRIO_HIGH, PRIO_NORMAL,
  PRIO_LOW, PRIO_LOWER, PRIO_LOWEST
}
 

Functions

ThreadPool::Ptr CpuBound ()
 
ThreadPool::Ptr Sequentially ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Priorities for scheduling on the ThreadPool

Enumerator
PRIO_HIGHEST 
PRIO_HIGHER 
PRIO_HIGH 
PRIO_NORMAL 
PRIO_LOW 
PRIO_LOWER 
PRIO_LOWEST 
25 {
26  PRIO_HIGHEST = 100,
28  PRIO_HIGH,
30  PRIO_LOW,
31  PRIO_LOWER,
33 };

Function Documentation

◆ CpuBound()

ThreadPool::Ptr CpuBound ( )

ThreadPool for cpu-bound tasks

This ThreadPool has one thread per core in your system. For CpuBound tasks, this is the optimum. Make sure your tasks do not block or wait for anything.

Returns
a shared pointer to this ThreadPool instance
See also
https://github.com/kees-jan/scroom/wiki/StaticInitializationOrderFiasco
453 {
454  static ThreadPool::Ptr const cpuBound = NotifyThreadList<ThreadPool>(ThreadPool::Ptr(new ThreadPool()), "CpuBound threadpool");
455 
456  return cpuBound;
457 }

Referenced by BOOST_AUTO_TEST_CASE(), Layer::fetchData(), CompressedTile::observerAdded(), and LayerCoordinator::tileFinished().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sequentially()

ThreadPool::Ptr Sequentially ( )

ThreadPool for executing tasks sequentially

Tasks that are cpu and/or memory intensive (think "loading large bitmaps") are typically scheduled here, such that only one such task runs at a time.

Note that it is rare to do any actual work on this thread. Especially the cpu-intensive tasks are best delegated to CpuBound(). On this thread, you just wait for the work to complete.

Returns
a shared pointer to this ThreadPool instance
See also
https://github.com/kees-jan/scroom/wiki/StaticInitializationOrderFiasco
460 {
461  static ThreadPool::Ptr const sequentially =
462  NotifyThreadList<ThreadPool>(ThreadPool::Ptr(new ThreadPool(1)), "Sequential threadpool");
463 
464  return sequentially;
465 }

Referenced by PipetteHandler::onSelectionEnd(), WaitForAsyncOp::operator()(), and Scroom::TiledBitmap::scheduleLoadingBitmap().

Here is the call graph for this function:
Here is the caller graph for this function:
ThreadPool::Ptr
boost::shared_ptr< ThreadPool > Ptr
Definition: threadpool.hh:169
PRIO_LOW
@ PRIO_LOW
Definition: threadpool.hh:30
ThreadPool
Definition: threadpool.hh:46
PRIO_LOWEST
@ PRIO_LOWEST
Definition: threadpool.hh:32
PRIO_LOWER
@ PRIO_LOWER
Definition: threadpool.hh:31
PRIO_HIGHEST
@ PRIO_HIGHEST
Definition: threadpool.hh:26
PRIO_HIGH
@ PRIO_HIGH
Definition: threadpool.hh:28
PRIO_HIGHER
@ PRIO_HIGHER
Definition: threadpool.hh:27
PRIO_NORMAL
@ PRIO_NORMAL
Definition: threadpool.hh:29