From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/interprocess/test/util.hpp | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/boost/libs/interprocess/test/util.hpp (limited to 'src/boost/libs/interprocess/test/util.hpp') diff --git a/src/boost/libs/interprocess/test/util.hpp b/src/boost/libs/interprocess/test/util.hpp new file mode 100644 index 00000000..c4e8229f --- /dev/null +++ b/src/boost/libs/interprocess/test/util.hpp @@ -0,0 +1,95 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2001-2003 +// William E. Kempf +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. William E. Kempf makes no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. + +#ifndef BOOST_INTERPROCESS_TEST_UTIL_HEADER +#define BOOST_INTERPROCESS_TEST_UTIL_HEADER + +#include +#include +#include + +#include +#include + +namespace boost { +namespace interprocess { +namespace test { + +inline void sleep(const boost::posix_time::ptime &xt) +{ + boost::interprocess::ipcdetail::thread_sleep + ((xt - microsec_clock::universal_time()).total_milliseconds()); +} + +inline boost::posix_time::ptime delay(int secs, int msecs=0, int nsecs = 0) +{ + (void)msecs; + using namespace boost::posix_time; + int count = static_cast(double(nsecs)* + (double(time_duration::ticks_per_second())/double(1000000000.0))); + count += static_cast(double(msecs)* + (double(time_duration::ticks_per_second())/double(1000.0))); + boost::posix_time::ptime cur = microsec_clock::universal_time(); + return cur += boost::posix_time::time_duration(0, 0, secs, count); +} + +inline bool in_range(const boost::posix_time::ptime& xt, int secs=1) +{ + boost::posix_time::ptime min = delay(-secs); + boost::posix_time::ptime max = delay(0); + return (xt > min) && (max > xt); +} + +template +class thread_adapter +{ + public: + thread_adapter(void (*func)(void*, P &), void* param1, P ¶m2) + : func_(func), param1_(param1) ,param2_(param2){ } + void operator()() const { func_(param1_, param2_); } + + private: + void (*func_)(void*, P &); + void* param1_; + P& param2_; +}; + +template +struct data +{ + explicit data(int id, int secs=0) + : m_id(id), m_value(-1), m_secs(secs), m_error(no_error) + {} + int m_id; + int m_value; + int m_secs; + error_code_t m_error; +}; + +static int shared_val = 0; +static const int BaseSeconds = 1; + +} //namespace test { +} //namespace interprocess { +} //namespace boost { + +#include + +#endif //#ifndef BOOST_INTERPROCESS_TEST_UTIL_HEADER -- cgit v1.2.3