the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 65 lines 1.7 kB view raw
1// Copyright (C) 2002-2003 2// David Moore, William E. Kempf 3// Copyright (C) 2007-8 Anthony Williams 4// 5// Distributed under the Boost Software License, Version 1.0. (See accompanying 6// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8#ifndef BOOST_BARRIER_JDM030602_HPP 9#define BOOST_BARRIER_JDM030602_HPP 10 11#include <boost/thread/detail/config.hpp> 12#include <boost/throw_exception.hpp> 13 14#include <boost/thread/mutex.hpp> 15#include <boost/thread/lock_types.hpp> 16#include <boost/thread/condition_variable.hpp> 17#include <string> 18#include <stdexcept> 19 20#include <boost/config/abi_prefix.hpp> 21 22namespace boost 23{ 24 25 class barrier 26 { 27 public: 28 barrier(unsigned int count) 29 : m_threshold(count), m_count(count), m_generation(0) 30 { 31 if (count == 0) 32 boost::throw_exception(thread_exception(system::errc::invalid_argument, "barrier constructor: count cannot be zero.")); 33 } 34 35 bool wait() 36 { 37 boost::unique_lock<boost::mutex> lock(m_mutex); 38 unsigned int gen = m_generation; 39 40 if (--m_count == 0) 41 { 42 m_generation++; 43 m_count = m_threshold; 44 m_cond.notify_all(); 45 return true; 46 } 47 48 while (gen == m_generation) 49 m_cond.wait(lock); 50 return false; 51 } 52 53 private: 54 mutex m_mutex; 55 condition_variable m_cond; 56 unsigned int m_threshold; 57 unsigned int m_count; 58 unsigned int m_generation; 59 }; 60 61} // namespace boost 62 63#include <boost/config/abi_suffix.hpp> 64 65#endif