#pragma once #include #include namespace RBX { namespace Test { template class TimeoutFixture { boost::thread thread; volatile bool done; boost::condition_variable cond; boost::mutex mut; void monitor() { boost::system_time const time = boost::get_system_time() + boost::posix_time::seconds(timeout); { boost::unique_lock lock(mut); if (!done) BOOST_REQUIRE_MESSAGE(cond.timed_wait(lock, time), "Timeout reached!"); } } public: TimeoutFixture() :done(false) { boost::unique_lock lock(mut); thread = boost::thread(boost::bind(&TimeoutFixture::monitor, this)); } ~TimeoutFixture() { { boost::unique_lock lock(mut); done = true; cond.notify_one(); } thread.join(); } }; }}