task_adaptors.hpp
来自「threadpool is a cross-platform C++ threa」· HPP 代码 · 共 94 行
HPP
94 行
/*! \file * \brief Task adaptors. * * This file contains adaptors for task function objects. * * Copyright (c) 2005-2006 Philipp Henkel * * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * http://threadpool.sourceforge.net * */#ifndef THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED#define THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED#include <boost/smart_ptr.hpp>#include "pool.hpp"namespace threadpool{/*! \brief Standard task function object. * * This function object wraps a function which gets no parameters and returns void. * The wrapped function is invoked by calling the operator (). * * \see boost function library * */ typedef boost::function0<void> thread_func; /*! \brief Prioritized task function object. * * This function object wraps a thread_func object and binds a priority to it. * prio_thread_funcs can be compared using the operator < which realises a partial ordering. * The wrapped task function is invoked by calling the operator (). * * \see prio_scheduler * */ class prio_thread_func{public: /*! Constructor. * \param priority The priority of the task. * \param function The task's function object. */ explicit prio_thread_func(unsigned int priority, thread_func function) : m_priority(priority) , m_function(function) { } /*! Executes the task function. */ void operator() (void) const { if(m_function) { m_function(); } } /*! Comparison operator which realises a partial ordering based on priorities. * \param right The object to compare with. * \return true if the priority of *this is less than right's priority, false otherwise. */ bool operator< (const prio_thread_func& right) const { return m_priority < right.m_priority; }private: unsigned int m_priority; //!< The priority of the task's function. thread_func m_function; //!< The task's function.};} // namespace threadpool#endif // THREADPOOL_TASK_ADAPTERS_HPP_INCLUDED
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?