Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/src/barrier.cpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 958 bytes
RevLine 
[29]1// Copyright (C) 2002-2003
2// David Moore, William E. Kempf
3//
4//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#include <boost/thread/detail/config.hpp>
8#include <boost/thread/barrier.hpp>
9#include <string> // see http://article.gmane.org/gmane.comp.lib.boost.devel/106981
10
11namespace boost {
12
13barrier::barrier(unsigned int count)
14    : m_threshold(count), m_count(count), m_generation(0)
15{
16    if (count == 0)
17        throw std::invalid_argument("count cannot be zero.");
18}
19
20barrier::~barrier()
21{
22}
23
24bool barrier::wait()
25{
26    boost::mutex::scoped_lock lock(m_mutex);
27    unsigned int gen = m_generation;
28
29    if (--m_count == 0)
30    {
31        m_generation++;
32        m_count = m_threshold;
33        m_cond.notify_all();
34        return true;
35    }
36
37    while (gen == m_generation)
38        m_cond.wait(lock);
39    return false;
40}
41
42} // namespace boost
Note: See TracBrowser for help on using the repository browser.