⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pool_adaptors.hpp

📁 threadpool is a cross-platform C++ thread pool library
💻 HPP
字号:
/*! \file * \brief Pool adaptors. * * This file contains an easy-to-use adaptor similar to a smart  * pointer for the pool class.  * * 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_POOL_ADAPTORS_HPP_INCLUDED#define THREADPOOL_POOL_ADAPTORS_HPP_INCLUDED#include <boost/smart_ptr.hpp>#include "pool.hpp"#include "schedulers.hpp"#include "task_adaptors.hpp"namespace threadpool{/*! \brief Pool smart pointer. * * A smart_pool holds a thread pool and behaves like a smart pointer to  * this pool. This class explicitly encourges object assigment and  * copy operations. * * \see pool * \see smart_fifo_pool, smart_lifo_pool, smart_prio_pool */ template <class Pool = pool<thread_func, fifo_scheduler<thread_func> > >class smart_pool{public:  typedef Pool pool_type;	//!< Provides the thread pool's type.  /*! Constructs a new thread pool.   * \param size The initial number of threads in the pool.   */  smart_pool(size_t size = 1)  {    m_pool = pool_type::create_pool(size);  }  /*! Uses an existing thread pool.   * \param pool The pool.   */  smart_pool(boost::shared_ptr<pool_type> pool)  : m_pool(pool)  {  }  /*! Destructor.   *  Terminates the thread pool and waits until termination is finished.   */  ~smart_pool()  {    m_pool->resize(0);		// trigger termination of all threads in pool    m_pool->join();			// wait until all threads are terminated  }  /*! Returns a reference to the stored pool.   * \return The pool reference.   */  pool_type& operator*() const  {  	return *m_pool.get();  }  /*! Returns stored pool pointer.   * \return The pool pointer.   */  pool_type* operator->() const  {  	return m_pool.get();  }private:	  boost::shared_ptr<pool_type> m_pool;		/// The managed pool pointer.};} // namespace threadpool#endif // THREADPOOL_POOL_ADAPTORS_HPP_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -