threadpool | Overview | Reference | Tutorial | Examples | Design

Reference | Class List | Member Functions | Typedefs | File List

/home/radek/Documents/threadpool-0_2_5-src/threadpool/boost/threadpool/pool.hpp
Go to the documentation of this file.

    00001
    00022 #ifndef THREADPOOL_POOL_HPP_INCLUDED
    00023 #define THREADPOOL_POOL_HPP_INCLUDED
    00024
    00025 #include <boost/ref.hpp>
    00026
    00027 #include "./detail/pool_core.hpp"
    00028
    00029 #include "task_adaptors.hpp"
    00030
    00031 #include "./detail/locking_ptr.hpp"
    00032
    00033 #include "scheduling_policies.hpp"
    00034 #include "size_policies.hpp"
    00035 #include "shutdown_policies.hpp"
    00036
    00037
    00038
    00040 namespace boost { namespace threadpool
    00041 {
    00042
    00043
    00044
    00066   template <
    00067     typename Task                                   = task_func,
    00068     template <typename> class SchedulingPolicy      = fifo_scheduler,
    00069     template <typename> class SizePolicy            = static_size,
    00070     template <typename> class SizePolicyController  = resize_controller,
    00071     template <typename> class ShutdownPolicy        = wait_for_all_tasks
    00072   >
    00073   class thread_pool
    00074   {
    00075     typedef detail::pool_core<Task,
    00076                               SchedulingPolicy,
    00077                               SizePolicy,
    00078                               SizePolicyController,
    00079                               ShutdownPolicy> pool_core_type;
    00080     shared_ptr<pool_core_type>          m_core; // pimpl idiom
    00081     shared_ptr<void>                    m_shutdown_controller; // If the last pool holding a pointer to the core is deleted the controller shuts the pool down.
    00082
    00083   public: // Type definitions
    00084     typedef Task task_type;
    00085     typedef SchedulingPolicy<task_type> scheduler_type;
    00086  /*   typedef thread_pool<Task,
    00087                         SchedulingPolicy,
    00088                         SizePolicy,
    00089                         ShutdownPolicy > pool_type;          //!< Indicates the thread pool's type.
    00090  */
    00091     typedef SizePolicy<pool_core_type> size_policy_type;
    00092     typedef SizePolicyController<pool_core_type> size_controller_type;
    00093
    00094
    00095   public:
    00099     thread_pool(size_t initial_threads = 0)
    00100     : m_core(new pool_core_type)
    00101     , m_shutdown_controller(static_cast<void*>(0), bind(&pool_core_type::shutdown, m_core))
    00102     {
    00103       size_policy_type::init(*m_core, initial_threads);
    00104     }
    00105
    00106
    00111     size_controller_type size_controller()
    00112     {
    00113       return m_core->size_controller();
    00114     }
    00115
    00116
    00120     size_t size() const
    00121     {
    00122       return m_core->size();
    00123     }
    00124
    00125
    00130      bool schedule(task_type const & task)
    00131      {
    00132        return m_core->schedule(task);
    00133      }
    00134
    00135
    00139     size_t active() const
    00140     {
    00141       return m_core->active();
    00142     }
    00143
    00144
    00148     size_t pending() const
    00149     {
    00150       return m_core->pending();
    00151     }
    00152
    00153
    00156     void clear()
    00157     {
    00158       m_core->clear();
    00159     }
    00160
    00161
    00166     bool empty() const
    00167     {
    00168       return m_core->empty();
    00169     }
    00170
    00171
    00176     void wait(size_t task_threshold = 0) const
    00177     {
    00178       m_core->wait(task_threshold);
    00179     }
    00180
    00181
    00189     bool wait(xtime const & timestamp, size_t task_threshold = 0) const
    00190     {
    00191       return m_core->wait(timestamp, task_threshold);
    00192     }
    00193   };
    00194
    00195
    00196
    00202   typedef thread_pool<task_func, fifo_scheduler, static_size, resize_controller, wait_for_all_tasks> fifo_pool;
    00203
    00204
    00210   typedef thread_pool<task_func, lifo_scheduler, static_size, resize_controller, wait_for_all_tasks> lifo_pool;
    00211
    00212
    00218   typedef thread_pool<prio_task_func, prio_scheduler, static_size, resize_controller, wait_for_all_tasks> prio_pool;
    00219
    00220
    00226   typedef fifo_pool pool;
    00227
    00228
    00229
    00230 } } // namespace boost::threadpool
    00231
    00232 #endif // THREADPOOL_POOL_HPP_INCLUDED

Copyright © 2005-2008 Philipp Henkel | Overview | Reference | Tutorial | Examples | Design