Go to the documentation of this file.
   39 #ifndef CGU_TASK_MANAGER_H 
   40 #define CGU_TASK_MANAGER_H 
   46 #include <type_traits>  
   62   virtual const char* 
what() 
const throw() {
return "TaskError\n";}
 
  410 #ifndef DOXYGEN_PARSING 
  416 namespace TaskManagerHelper2 {
 
  418 template <
class Ret, 
class FType>
 
  419 struct FunctorResultWrapper {
 
  420   static void exec(FType& f,
 
  424   static void do_fail(
const SharedLockPtr<AsyncResult<Ret>>& ret) {
 
  444 template <
class Ret, 
class FType>
 
  446   mutable FType functor;
 
  447   SharedLockPtr<AsyncResult<Ret>> ret;
 
  452   template <
class FunctorArg>
 
  453   FunctorResultExec(FunctorArg&& functor_,
 
  454             const SharedLockPtr<AsyncResult<Ret>>& ret_): functor(std::forward<FunctorArg>(functor_)),
 
  459 #endif // DOXYGEN_PARSING 
  467   typedef std::pair<std::unique_ptr<const Callback::Callback>,
 
  468                     std::unique_ptr<const Callback::Callback>> QueueItemType;
 
  478   static unsigned int init_max_tasks();
 
  660     static unsigned int max_tasks = init_max_tasks();
 
  843 #ifdef CGU_USE_AUTO_PTR 
  844     add_task(std::auto_ptr<const Callback::Callback>(task),
 
  845          std::auto_ptr<const Callback::Callback>());
 
  847     add_task(std::unique_ptr<const Callback::Callback>(task),
 
  848          std::unique_ptr<const Callback::Callback>());
 
  924 #ifdef CGU_USE_AUTO_PTR 
  925   void add_task(std::auto_ptr<const Callback::Callback> task,
 
  926         std::auto_ptr<const Callback::Callback> fail);
 
  928   void add_task(std::unique_ptr<const Callback::Callback> task,
 
  929         std::unique_ptr<const Callback::Callback> fail);
 
 1001   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1003                                  Ret (T::*func)(Params...),
 
 1137   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1138 #ifdef CGU_USE_AUTO_PTR 
 1141                std::auto_ptr<const Cgu::Callback::Callback> fail,
 
 1144                GMainContext* context,
 
 1146                Ret (T::*func)(Params...),
 
 1151                std::unique_ptr<const Cgu::Callback::Callback> fail,
 
 1154                GMainContext* context,
 
 1156                Ret (T::*func)(Params...),
 
 1247   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1248 #ifdef CGU_USE_AUTO_PTR 
 1250               GMainContext* context,
 
 1252               Ret (T::*func)(Params...),
 
 1254     static_assert(
sizeof...(Args) < 4,
 
 1255           "No greater than three bound arguments can be passed to " 
 1256           "TaskManager::make_task_when() taking a member function.");
 
 1260             std::auto_ptr<const Cgu::Callback::Callback>(),
 
 1266             std::forward<Args>(args)...);
 
 1270               GMainContext* context,
 
 1272               Ret (T::*func)(Params...),
 
 1274     static_assert(
sizeof...(Args) < 4,
 
 1275           "No greater than three bound arguments can be passed to " 
 1276           "TaskManager::make_task_when() taking a member function.");
 
 1280             std::unique_ptr<const Cgu::Callback::Callback>(),
 
 1286             std::forward<Args>(args)...);
 
 1341   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1343                                  Ret (T::*func)(Params...) 
const,
 
 1477   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1478 #ifdef CGU_USE_AUTO_PTR 
 1481                std::auto_ptr<const Cgu::Callback::Callback> fail,
 
 1484                GMainContext* context,
 
 1486                Ret (T::*func)(Params...) 
const,
 
 1491                std::unique_ptr<const Cgu::Callback::Callback> fail,
 
 1494                GMainContext* context,
 
 1496                Ret (T::*func)(Params...) 
const,
 
 1587   template <
class Ret, 
class... Params, 
class... Args, 
class T>
 
 1588 #ifdef CGU_USE_AUTO_PTR 
 1590               GMainContext* context,
 
 1592               Ret (T::*func)(Params...) 
const,
 
 1594     static_assert(
sizeof...(Args) < 4,
 
 1595           "No greater than three bound arguments can be passed to " 
 1596           "TaskManager::make_task_when() taking a member function.");
 
 1600             std::auto_ptr<const Cgu::Callback::Callback>(),
 
 1606             std::forward<Args>(args)...);
 
 1610               GMainContext* context,
 
 1612               Ret (T::*func)(Params...) 
const,
 
 1614     static_assert(
sizeof...(Args) < 4,
 
 1615           "No greater than three bound arguments can be passed to " 
 1616           "TaskManager::make_task_when() taking a member function.");
 
 1620             std::unique_ptr<const Cgu::Callback::Callback>(),
 
 1626             std::forward<Args>(args)...);
 
 1678   template <
class Ret, 
class... Params, 
class... Args>
 
 1811   template <
class Ret, 
class... Params, 
class... Args>
 
 1812 #ifdef CGU_USE_AUTO_PTR 
 1815                std::auto_ptr<const Cgu::Callback::Callback> fail,
 
 1818                GMainContext* context,
 
 1819                Ret (*func)(Params...),
 
 1824                std::unique_ptr<const Cgu::Callback::Callback> fail,
 
 1827                GMainContext* context,
 
 1828                Ret (*func)(Params...),
 
 1916   template <
class Ret, 
class... Params, 
class... Args>
 
 1917 #ifdef CGU_USE_AUTO_PTR 
 1919               GMainContext* context,
 
 1920               Ret (*func)(Params...),
 
 1922     static_assert(
sizeof...(Args) < 5,
 
 1923           "No greater than four bound arguments can be passed to " 
 1924           "TaskManager::make_task_when() taking a function.");
 
 1928             std::auto_ptr<const Cgu::Callback::Callback>(),
 
 1933             std::forward<Args>(args)...);
 
 1936               GMainContext* context,
 
 1937               Ret (*func)(Params...),
 
 1939     static_assert(
sizeof...(Args) < 5,
 
 1940           "No greater than four bound arguments can be passed to " 
 1941           "TaskManager::make_task_when() taking a function.");
 
 1945             std::unique_ptr<const Cgu::Callback::Callback>(),
 
 1950             std::forward<Args>(args)...);
 
 2028   template <
class Ret, 
class Func>
 
 2034 #ifndef DOXYGEN_PARSING 
 2035   template <
class Func>
 
 2054     typedef typename std::remove_const<typename std::remove_reference<Func>::type>::type FType;
 
 2059     typedef decltype(f()) Ret;
 
 2060 #ifdef CGU_USE_AUTO_PTR 
 2061     typedef std::auto_ptr<const Callback::Callback> CbPtr;
 
 2063     typedef std::unique_ptr<const Callback::Callback> CbPtr;
 
 2067     CbPtr exec_cb(
new TaskManagerHelper2::FunctorResultExec<Ret, FType>(std::forward<Func>(f), ret));
 
 2068     CbPtr do_fail_cb(
Callback::make_ref(&TaskManagerHelper2::FunctorResultWrapper<Ret, FType>::do_fail,
 
 2070     add_task(std::move(exec_cb), std::move(do_fail_cb));
 
 2215   template <
class Ret, 
class Func>
 
 2216 #ifdef CGU_USE_AUTO_PTR 
 2219                std::auto_ptr<const Cgu::Callback::Callback> fail,
 
 2222                GMainContext* context,
 
 2227                std::unique_ptr<const Cgu::Callback::Callback> fail,
 
 2230                GMainContext* context,
 
 2329   template <
class Ret, 
class Func>
 
 2330 #ifdef CGU_USE_AUTO_PTR 
 2332               GMainContext* context,
 
 2336             std::auto_ptr<const Cgu::Callback::Callback>(),
 
 2340             std::forward<Func>(f));
 
 2344               GMainContext* context,
 
 2348             std::unique_ptr<const Cgu::Callback::Callback>(),
 
 2352                         std::forward<Func>(f));
 
 2452   template <
class Ret, 
class Func>
 
 2453 #ifdef CGU_USE_AUTO_PTR 
 2455              GMainContext* context,
 
 2459             std::auto_ptr<const Cgu::Callback::Callback>(),
 
 2463             std::forward<Func>(f));
 
 2467              GMainContext* context,
 
 2471             std::unique_ptr<const Cgu::Callback::Callback>(),
 
 2475                         std::forward<Func>(f));
 
 2551   TaskManager(
unsigned int max = 8, 
unsigned int min = 0,
 
 2552               unsigned int idle = 10000, 
bool blocking = 
true,
 
 2694 #include <c++-gtk-utils/task_manager.tpp> 
  
StopMode
Definition: task_manager.h:464
void make_task_when(std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when, GMainContext *context, const T &t, Ret(T::*func)(Params...) const, Args &&... args)
Definition: task_manager.h:1609
CallbackArg< FreeArgs... > * make_ref(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1695
The callback interface class.
Definition: callback.h:522
Definition: application.h:44
virtual const char * what() const
Definition: task_manager.h:62
void make_task_compose(Func &&f, GMainContext *context, std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when)
Definition: task_manager.h:2466
Definition: task_manager.h:61
void make_task_when(std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when, GMainContext *context, Ret(*func)(Params...), Args &&... args)
Definition: task_manager.h:1935
void set_max_threads(unsigned int max)
void make_task_when_full(std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when, Cgu::Releaser *when_releaser, std::unique_ptr< const Cgu::Callback::Callback > fail, Cgu::Releaser *fail_releaser, gint priority, GMainContext *context, T &t, Ret(T::*func)(Params...), Args &&... args)
TaskManager & operator=(const TaskManager &)=delete
unsigned int get_idle_time() const
This file provides classes for type erasure.
bool get_blocking() const
A scoped locking class for exception safe Mutex locking which tracks the status of its mutex.
Definition: mutex.h:331
A thread-safe asynchronous result class.
Definition: async_result.h:165
unsigned int get_min_threads() const
Cgu::SharedLockPtr< Cgu::AsyncResult< Ret > > make_task_result(T &t, Ret(T::*func)(Params...), Args &&... args)
This file provides thread-safe asynchronous queue classes.
unsigned int get_used_threads() const
unsigned int get_tasks() const
static unsigned int get_max_tasks()
Definition: task_manager.h:653
auto exec(const std::string &preamble, const std::string &file, Translator translator) -> typename std::result_of< Translator(SCM)>::type
Definition: extension.h:1702
TaskManager(const TaskManager &)=delete
void set_idle_time(unsigned int idle)
IncHandle(TaskManager &tm_)
Definition: task_manager.h:2676
This file provides a thread-safe asynchronous result class.
@ wait_for_all
Definition: task_manager.h:464
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition: cgu_config.h:84
void set_stop_mode(StopMode mode)
Provides wrapper classes for pthread mutexes and condition variables, and scoped locking classes for ...
This is a smart pointer for managing the lifetime of objects allocated on freestore,...
Definition: shared_ptr.h:644
void change_max_threads(int delta)
A scoped handle for exception safe incrementing of the maximum number of threads that a TaskManager o...
Definition: task_manager.h:2630
A class used for tracking EmitterArg and SafeEmitterArg connections.
Definition: emitter.h:333
void add_task(const Callback::Callback *task)
Definition: task_manager.h:842
StopMode get_stop_mode() const
~IncHandle()
Definition: task_manager.h:2687
void make_task_when(std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when, GMainContext *context, Func &&f)
Definition: task_manager.h:2343
This file provides a thread-safe signal/slot mechanism, with automatic disconnection.
void make_task_when(std::unique_ptr< const Cgu::Callback::CallbackArg< const Ret & >> when, GMainContext *context, T &t, Ret(T::*func)(Params...), Args &&... args)
Definition: task_manager.h:1269
A thread-pool class for managing tasks in multi-threaded programs.
Definition: task_manager.h:462
void set_blocking(bool blocking)
@ wait_for_running
Definition: task_manager.h:464
unsigned int get_max_threads() const