Barrier.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Based on barrier.hpp from Boost 1.51
// Copyright (C) 2002-2003
// David Moore, William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
// Which was distributed under the Boost Software License, Version 1.0.
// (See accomanying NOTICES or a copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef SURGSIM_FRAMEWORK_BARRIER_H
#define SURGSIM_FRAMEWORK_BARRIER_H
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <string>
#include <stdexcept>
#include "SurgSim/Framework/Assert.h"
namespace SurgSim
{
namespace Framework
{
class Barrier
{
public:
explicit Barrier(size_t count);
bool wait(bool success);
private:
boost::mutex m_mutex;
boost::condition_variable m_cond;
size_t m_threshold;
size_t m_count;
size_t m_generation;
bool m_success;
bool m_successResult;
};
} // namespace Framework
} // namespace SurgSim
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Barrier::m_threshold
size_t m_threshold
Definition: Barrier.h:66
SurgSim::Framework::Barrier::m_success
bool m_success
Definition: Barrier.h:69
SurgSim::Framework::Barrier::m_generation
size_t m_generation
Definition: Barrier.h:68
SurgSim::Framework::Barrier::m_cond
boost::condition_variable m_cond
Definition: Barrier.h:65
SurgSim::Framework::Barrier::wait
bool wait(bool success)
Waits until all count threads have called wait.
Definition: Barrier.cpp:35
SurgSim::Framework::Barrier::m_mutex
boost::mutex m_mutex
Definition: Barrier.h:64
SurgSim::Framework::Barrier::m_count
size_t m_count
Definition: Barrier.h:67
SurgSim::Framework::Barrier::Barrier
Barrier(size_t count)
Construct the barrier.
Definition: Barrier.cpp:26
SurgSim::Framework::Barrier
Barrier class, synchronize a set of threads to wait at a common point, all threads will wait at Barri...
Definition: Barrier.h:45
SurgSim::Framework::Barrier::m_successResult
bool m_successResult
Definition: Barrier.h:70
Assert.h
The header that provides the assertion API.