1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 // Copyright (C) 2001-2003
13 // Permission to use, copy, modify, distribute and sell this software
14 // and its documentation for any purpose is hereby granted without fee,
15 // provided that the above copyright notice appear in all copies and
16 // that both that copyright notice and this permission notice appear
17 // in supporting documentation. William E. Kempf makes no representations
18 // about the suitability of this software for any purpose.
19 // It is provided "as is" without express or implied warranty.
21 #ifndef BOOST_CONTAINER_TEST_UTIL_HEADER
22 #define BOOST_CONTAINER_TEST_UTIL_HEADER
24 #include <boost/container/detail/config_begin.hpp>
25 #include <boost/container/sync/container_mutex.hpp>
26 #include <boost/container/sync/container_condition.hpp>
27 #include <boost/container/sync/scoped_lock.hpp>
28 #include <boost/thread/thread.hpp>
29 #include <boost/thread/xtime.hpp>
31 #include <boost/date_time/posix_time/posix_time_types.hpp>
35 #ifndef DEFAULT_EXECUTION_MONITOR_TYPE
36 # define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_condition
43 inline void sleep(const boost::posix_time::ptime &xt)
45 boost::container::container_mutex mx;
46 boost::container::scoped_lock<boost::container::container_mutex>
48 boost::container::container_condition cond;
49 cond.timed_wait(lock, xt);
52 inline boost::posix_time::ptime delay(int secs, int msecs=0, int nsecs = 0)
55 using namespace boost::posix_time;
56 int count = static_cast<int>(double(nsecs)*
57 (double(time_duration::ticks_per_second())/double(1000000000.0)));
58 count += static_cast<int>(double(msecs)*
59 (double(time_duration::ticks_per_second())/double(1000.0)));
60 boost::posix_time::ptime cur = microsec_clock::universal_time();
61 return cur += boost::posix_time::time_duration(0, 0, secs, count);
64 inline bool in_range(const boost::posix_time::ptime& xt, int secs=1)
66 boost::posix_time::ptime min = delay(-secs);
67 boost::posix_time::ptime max = delay(0);
68 return (xt > min) && (max > xt);
71 boost::xtime xsecs(int secs)
74 boost::xtime_get(&ret, boost::TIME_UTC);
83 thread_adapter(void (*func)(void*, P &), void* param1, P ¶m2)
84 : _func(func), _param1(param1) ,_param2(param2){ }
85 void operator()() const { _func(_param1, _param2); }
88 void (*_func)(void*, P &);
96 data(int id, int secs=0)
97 : m_id(id), m_value(-1), m_secs(secs)
104 static int shared_val = 0;
105 static const int BaseSeconds = 1;
108 } //namespace container {
109 } //namespace boost {
111 #include <boost/container/detail/config_end.hpp>
113 #endif //#ifndef BOOST_CONTAINER_TEST_UTIL_HEADER