shutdown_policies.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*! \file
  2. * \brief Shutdown policies.
  3. *
  4. * This file contains shutdown policies for thread_pool.
  5. * A shutdown policy controls the pool's behavior from the time
  6. * when the pool is not referenced any longer.
  7. *
  8. * Copyright (c) 2005-2007 Philipp Henkel
  9. *
  10. * Use, modification, and distribution are subject to the
  11. * Boost Software License, Version 1.0. (See accompanying file
  12. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. *
  14. * http://threadpool.sourceforge.net
  15. *
  16. */
  17. #ifndef THREADPOOL_SHUTDOWN_POLICIES_HPP_INCLUDED
  18. #define THREADPOOL_SHUTDOWN_POLICIES_HPP_INCLUDED
  19. /// The namespace threadpool contains a thread pool and related utility classes.
  20. namespace boost { namespace threadpool
  21. {
  22. /*! \brief ShutdownPolicy which waits for the completion of all tasks
  23. * and the worker termination afterwards.
  24. *
  25. * \param Pool The pool's core type.
  26. */
  27. template<typename Pool>
  28. class wait_for_all_tasks
  29. {
  30. public:
  31. static void shutdown(Pool& pool)
  32. {
  33. pool.wait();
  34. pool.terminate_all_workers(true);
  35. }
  36. };
  37. /*! \brief ShutdownPolicy which waits for the completion of all active tasks
  38. * and the worker termination afterwards.
  39. *
  40. * \param Pool The pool's core type.
  41. */
  42. template<typename Pool>
  43. class wait_for_active_tasks
  44. {
  45. public:
  46. static void shutdown(Pool& pool)
  47. {
  48. pool.clear();
  49. pool.wait();
  50. pool.terminate_all_workers(true);
  51. }
  52. };
  53. /*! \brief ShutdownPolicy which does not wait for any tasks or worker termination.
  54. *
  55. * This policy does not wait for any tasks. Nevertheless all active tasks will be processed completely.
  56. *
  57. * \param Pool The pool's core type.
  58. */
  59. template<typename Pool>
  60. class immediately
  61. {
  62. public:
  63. static void shutdown(Pool& pool)
  64. {
  65. pool.clear();
  66. pool.terminate_all_workers(false);
  67. }
  68. };
  69. } } // namespace boost::threadpool
  70. #endif // THREADPOOL_SHUTDOWN_POLICIES_HPP_INCLUDED