1 // Copyright (C) 2013 Vicente Botet
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //#include <boost/log/trivial.hpp>
9 #include <boost/chrono.hpp>
10 #include <boost/thread.hpp>
11 #include <boost/thread/condition_variable.hpp>
13 //#if !defined(BOOST_NO_CXX11_ALIGNAS)
15 //# define BOOST_ALIGNMENT2(x) alignas(x)
16 //#elif defined(_MSC_VER)
18 //# define BOOST_ALIGNMENT2(x) __declspec(align(x))
19 //#elif defined(__GNUC__)
21 //# define BOOST_ALIGNMENT(x) __attribute__ ((__aligned__(x)))
24 //# define BOOST_NO_ALIGNMENT2
25 //# define BOOST_ALIGNMENT2(x)
28 typedef boost::chrono::high_resolution_clock Clock
;
29 typedef Clock::time_point TimePoint
;
31 inline TimePoint
real_time_now()
38 using namespace boost::chrono
;
40 boost::condition_variable m_task_spawn_condition
;
42 boost::mutex main_thread_mutex
;
43 boost::unique_lock
< boost::mutex
> main_thread_lock(main_thread_mutex
);
45 //BOOST_LOG_TRIVIAL(info) << "[TaskScheduler::run_and_wait] Scheduling loop - BEGIN";
49 static const milliseconds TIME_BACK
= milliseconds(1);
50 m_task_spawn_condition
.wait_until(
52 real_time_now() - TIME_BACK
); // wait forever
53 m_task_spawn_condition
.wait_for( main_thread_lock
, - TIME_BACK
); // same problem
54 //BOOST_LOG_TRIVIAL(trace) << "TICK";