/Src/Dependencies/Boost/boost/interprocess/sync/interprocess_barrier.hpp

http://hadesmem.googlecode.com/ · C++ Header · 115 lines · 51 code · 18 blank · 46 comment · 2 complexity · 0eeebb70b11725ce444d7e29a04869d1 MD5 · raw file

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // barrier is a modified version of Boost Threads barrier
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Copyright (C) 2002-2003
  16. // David Moore, William E. Kempf
  17. //
  18. // Permission to use, copy, modify, distribute and sell this software
  19. // and its documentation for any purpose is hereby granted without fee,
  20. // provided that the above copyright notice appear in all copies and
  21. // that both that copyright notice and this permission notice appear
  22. // in supporting documentation. William E. Kempf makes no representations
  23. // about the suitability of this software for any purpose.
  24. // It is provided "as is" without express or implied warranty.
  25. #ifndef BOOST_INTERPROCESS_BARRIER_HPP
  26. #define BOOST_INTERPROCESS_BARRIER_HPP
  27. /// @cond
  28. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  29. # pragma once
  30. #endif
  31. #include <boost/interprocess/detail/config_begin.hpp>
  32. #include <boost/interprocess/detail/workaround.hpp>
  33. #if defined BOOST_INTERPROCESS_POSIX_PROCESS_SHARED && defined BOOST_INTERPROCESS_POSIX_BARRIERS
  34. # include <pthread.h>
  35. # include <errno.h>
  36. # include <boost/interprocess/sync/posix/pthread_helpers.hpp>
  37. # define BOOST_INTERPROCESS_USE_POSIX
  38. #else
  39. # include <boost/interprocess/sync/interprocess_mutex.hpp>
  40. # include <boost/interprocess/sync/scoped_lock.hpp>
  41. # include <boost/interprocess/sync/interprocess_condition.hpp>
  42. # include <stdexcept>
  43. # define BOOST_INTERPROCESS_USE_GENERIC_EMULATION
  44. #endif
  45. # include <boost/interprocess/exceptions.hpp>
  46. /// @endcond
  47. namespace boost {
  48. namespace interprocess {
  49. //!An object of class barrier is a synchronization primitive that
  50. //!can be placed in shared memory used to cause a set of threads from
  51. //!different processes to wait until they each perform a certain
  52. //!function or each reach a particular point in their execution.
  53. class barrier
  54. {
  55. public:
  56. //!Constructs a barrier object that will cause count threads
  57. //!to block on a call to wait().
  58. barrier(unsigned int count);
  59. //!Destroys *this. If threads are still executing their wait()
  60. //!operations, the behavior for these threads is undefined.
  61. ~barrier();
  62. //!Effects: Wait until N threads call wait(), where N equals the count
  63. //!provided to the constructor for the barrier object.
  64. //!Note that if the barrier is destroyed before wait() can return,
  65. //!the behavior is undefined.
  66. //!Returns: Exactly one of the N threads will receive a return value
  67. //!of true, the others will receive a value of false. Precisely which
  68. //!thread receives the return value of true will be implementation-defined.
  69. //!Applications can use this value to designate one thread as a leader that
  70. //!will take a certain action, and the other threads emerging from the barrier
  71. //!can wait for that action to take place.
  72. bool wait();
  73. /// @cond
  74. private:
  75. #if defined(BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
  76. interprocess_mutex m_mutex;
  77. interprocess_condition m_cond;
  78. unsigned int m_threshold;
  79. unsigned int m_count;
  80. unsigned int m_generation;
  81. #else //#if defined BOOST_INTERPROCESS_USE_POSIX
  82. pthread_barrier_t m_barrier;
  83. #endif//#if defined BOOST_INTERPROCESS_USE_POSIX
  84. /// @endcond
  85. };
  86. } // namespace interprocess
  87. } // namespace boost
  88. #ifdef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
  89. # undef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
  90. # include <boost/interprocess/sync/emulation/interprocess_barrier.hpp>
  91. #endif
  92. #ifdef BOOST_INTERPROCESS_USE_POSIX
  93. # undef BOOST_INTERPROCESS_USE_POSIX
  94. # include <boost/interprocess/sync/posix/interprocess_barrier.hpp>
  95. #endif
  96. #include <boost/interprocess/detail/config_end.hpp>
  97. #endif