PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 26#ifndef BOOST_INTERPROCESS_BARRIER_HPP
 27#define BOOST_INTERPROCESS_BARRIER_HPP
 28
 29/// @cond
 30
 31#if (defined _MSC_VER) && (_MSC_VER >= 1200)
 32#  pragma once
 33#endif
 34
 35#include <boost/interprocess/detail/config_begin.hpp>
 36#include <boost/interprocess/detail/workaround.hpp>
 37
 38#if defined BOOST_INTERPROCESS_POSIX_PROCESS_SHARED && defined BOOST_INTERPROCESS_POSIX_BARRIERS
 39#  include <pthread.h>
 40#  include <errno.h>   
 41#  include <boost/interprocess/sync/posix/pthread_helpers.hpp>
 42#  define BOOST_INTERPROCESS_USE_POSIX
 43#else
 44#  include <boost/interprocess/sync/interprocess_mutex.hpp>
 45#  include <boost/interprocess/sync/scoped_lock.hpp>
 46#  include <boost/interprocess/sync/interprocess_condition.hpp>
 47#  include <stdexcept>
 48#  define BOOST_INTERPROCESS_USE_GENERIC_EMULATION
 49#endif
 50
 51#  include <boost/interprocess/exceptions.hpp>
 52
 53/// @endcond
 54
 55namespace boost {
 56namespace interprocess {
 57
 58//!An object of class barrier is a synchronization primitive that 
 59//!can be placed in shared memory used to cause a set of threads from 
 60//!different processes to wait until they each perform a certain 
 61//!function or each reach a particular point in their execution.
 62class barrier
 63{
 64   public:
 65   //!Constructs a barrier object that will cause count threads 
 66   //!to block on a call to wait().
 67   barrier(unsigned int count);
 68
 69   //!Destroys *this. If threads are still executing their wait() 
 70   //!operations, the behavior for these threads is undefined.
 71   ~barrier();
 72
 73   //!Effects: Wait until N threads call wait(), where N equals the count 
 74   //!provided to the constructor for the barrier object.
 75   //!Note that if the barrier is destroyed before wait() can return, 
 76   //!the behavior is undefined.
 77   //!Returns: Exactly one of the N threads will receive a return value 
 78   //!of true, the others will receive a value of false. Precisely which 
 79   //!thread receives the return value of true will be implementation-defined. 
 80   //!Applications can use this value to designate one thread as a leader that 
 81   //!will take a certain action, and the other threads emerging from the barrier 
 82   //!can wait for that action to take place.
 83   bool wait();
 84
 85   /// @cond
 86   private:
 87   #if defined(BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
 88      interprocess_mutex m_mutex;
 89      interprocess_condition m_cond;
 90      unsigned int m_threshold;
 91      unsigned int m_count;
 92      unsigned int m_generation;
 93   #else //#if defined BOOST_INTERPROCESS_USE_POSIX
 94      pthread_barrier_t    m_barrier;
 95   #endif//#if defined BOOST_INTERPROCESS_USE_POSIX
 96   /// @endcond
 97};
 98
 99}  // namespace interprocess
100}  // namespace boost
101
102
103#ifdef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
104#  undef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
105#  include <boost/interprocess/sync/emulation/interprocess_barrier.hpp>
106#endif
107
108#ifdef BOOST_INTERPROCESS_USE_POSIX
109#  undef BOOST_INTERPROCESS_USE_POSIX
110#  include <boost/interprocess/sync/posix/interprocess_barrier.hpp>
111#endif
112
113#include <boost/interprocess/detail/config_end.hpp>
114
115#endif