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/scheduling_policies.hpp
Go to the documentation of this file.

    00001
    00022 #ifndef THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
    00023 #define THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
    00024
    00025
    00026 #include <queue>
    00027 #include <deque>
    00028
    00029 #include "task_adaptors.hpp"
    00030
    00031 namespace boost { namespace threadpool
    00032 {
    00033
    00044   template <typename Task = task_func>
    00045   class fifo_scheduler
    00046   {
    00047   public:
    00048     typedef Task task_type;
    00049
    00050   protected:
    00051     std::deque<task_type> m_container;
    00052
    00053
    00054   public:
    00059     bool push(task_type const & task)
    00060     {
    00061       m_container.push_back(task);
    00062       return true;
    00063     }
    00064
    00067     void pop()
    00068     {
    00069       m_container.pop_front();
    00070     }
    00071
    00075     task_type const & top() const
    00076     {
    00077       return m_container.front();
    00078     }
    00079
    00084     size_t size() const
    00085     {
    00086       return m_container.size();
    00087     }
    00088
    00093     bool empty() const
    00094     {
    00095       return m_container.empty();
    00096     }
    00097
    00100     void clear()
    00101     {
    00102       m_container.clear();
    00103     }
    00104   };
    00105
    00106
    00107
    00117   template <typename Task = task_func>
    00118   class lifo_scheduler
    00119   {
    00120   public:
    00121     typedef Task task_type;
    00122
    00123   protected:
    00124     std::deque<task_type> m_container;
    00125
    00126   public:
    00131     bool push(task_type const & task)
    00132     {
    00133       m_container.push_front(task);
    00134       return true;
    00135     }
    00136
    00139     void pop()
    00140     {
    00141       m_container.pop_front();
    00142     }
    00143
    00147     task_type const & top() const
    00148     {
    00149       return m_container.front();
    00150     }
    00151
    00156     size_t size() const
    00157     {
    00158       return m_container.size();
    00159     }
    00160
    00165     bool empty() const
    00166     {
    00167       return m_container.empty();
    00168     }
    00169
    00172     void clear()
    00173     {
    00174       m_container.clear();
    00175     }
    00176
    00177   };
    00178
    00179
    00180
    00192   template <typename Task = prio_task_func>
    00193   class prio_scheduler
    00194   {
    00195   public:
    00196     typedef Task task_type;
    00197
    00198   protected:
    00199     std::priority_queue<task_type> m_container;
    00200
    00201
    00202   public:
    00207     bool push(task_type const & task)
    00208     {
    00209       m_container.push(task);
    00210       return true;
    00211     }
    00212
    00215     void pop()
    00216     {
    00217       m_container.pop();
    00218     }
    00219
    00223     task_type const & top() const
    00224     {
    00225       return m_container.top();
    00226     }
    00227
    00232     size_t size() const
    00233     {
    00234       return m_container.size();
    00235     }
    00236
    00241     bool empty() const
    00242     {
    00243       return m_container.empty();
    00244     }
    00245
    00248     void clear()
    00249     {
    00250       while(!m_container.empty())
    00251       {
    00252         m_container.pop();
    00253       }
    00254     }
    00255   };
    00256
    00257
    00258 } } // namespace boost::threadpool
    00259
    00260
    00261 #endif // THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
    00262

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