File: util.hpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (178 lines) | stat: -rw-r--r-- 5,954 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//////////////////////////////////////////////////////////////////////////////
//
// (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 <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/detail/os_thread_functions.hpp>
#include <boost/interprocess/timed_utils.hpp>

#if defined(BOOST_CLANG) || (defined(BOOST_GCC) && (BOOST_GCC >= 40600))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wcast-align"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#  if (BOOST_GCC >= 100000)
#pragma GCC diagnostic ignored "-Warith-conversion"
#  endif
#endif

#if (BOOST_CXX_VERSION >= 201103L) && (!defined(BOOST_GCC) || (BOOST_GCC >= 40800))
//boost.System is not tested under GCC <= 4.8 and has compilation errors
//due to incomplete language support in older compilers
#define BOOST_INTERPROCESS_BOOST_CHRONO_AVAILABLE
#endif

#if (BOOST_CXX_VERSION >= 201103L)
#define BOOST_INTERPROCESS_DATE_TIME_AVAILABLE
#include <boost/date_time/posix_time/posix_time_types.hpp>
#endif

#ifdef BOOST_INTERPROCESS_BOOST_CHRONO_AVAILABLE
#define BOOST_CHRONO_HEADER_ONLY
#include <boost/chrono/system_clocks.hpp>
#endif

#include <boost/version.hpp>

#if !defined(BOOST_NO_CXX11_HDR_CHRONO)
#include <chrono>
#endif

#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif

namespace boost {
namespace interprocess {
namespace test {

// ptime_delay_ms + ptime_ms

#if defined(BOOST_INTERPROCESS_DATE_TIME_AVAILABLE)
inline boost::posix_time::ptime ptime_delay_ms(unsigned msecs)
{
   using namespace boost::posix_time;
   int count = static_cast<int>(double(msecs) *
      (double(time_duration::ticks_per_second()) / double(1000.0)));
   return microsec_clock::universal_time() + time_duration(0, 0, 0, count);
}

inline boost::posix_time::time_duration ptime_ms(unsigned msecs)
{
   using namespace boost::posix_time;
   int count = static_cast<int>(double(msecs) *
      (double(time_duration::ticks_per_second()) / double(1000.0)));
   return time_duration(0, 0, 0, count);
}
#else
   inline ustime ptime_delay_ms(unsigned msecs)
   {  return ustime_delay_milliseconds(msecs); }

   inline usduration ptime_ms(unsigned msecs)
   {  return usduration_from_milliseconds(msecs); }
#endif

// boost_systemclock_delay_ms + boost_systemclock_ms

#if defined(BOOST_INTERPROCESS_BOOST_CHRONO_AVAILABLE)
   inline boost::chrono::system_clock::time_point boost_systemclock_delay_ms(unsigned msecs)
   {  return boost::chrono::system_clock::now() + boost::chrono::milliseconds(msecs);  }

   inline boost::chrono::milliseconds boost_systemclock_ms(unsigned msecs)
   {  return boost::chrono::milliseconds(msecs);  }
#else
   inline ustime boost_systemclock_delay_ms(unsigned msecs)
   {  return ustime_delay_milliseconds(msecs); }

   inline usduration boost_systemclock_ms(unsigned msecs)
   {  return usduration_from_milliseconds(msecs); }
#endif 

// std_systemclock_delay_ms + std_systemclock_ms

#if !defined(BOOST_NO_CXX11_HDR_CHRONO)
   //Use std chrono if available
   inline std::chrono::system_clock::time_point std_systemclock_delay_ms(unsigned msecs)
   {  return std::chrono::system_clock::now() + std::chrono::milliseconds(msecs);  }

   inline std::chrono::milliseconds std_systemclock_ms(unsigned msecs)
   {  return std::chrono::milliseconds(msecs);  }

#elif defined(BOOST_INTERPROCESS_BOOST_CHRONO_AVAILABLE)
   //Otherwise use boost chrono
   inline boost::chrono::system_clock::time_point std_systemclock_delay_ms(unsigned msecs)
   {  return boost_systemclock_delay_ms(msecs);  }

   inline boost::chrono::milliseconds std_systemclock_ms(unsigned msecs)
   {  return boost_systemclock_ms(msecs);  }
#else
   inline ustime std_systemclock_delay_ms(unsigned msecs)
   {  return ustime_delay_milliseconds(msecs); }

   inline usduration std_systemclock_ms(unsigned msecs)
   {  return usduration_from_milliseconds(msecs); }
#endif

// thread_adapter + data

template <typename P>
class thread_adapter
{
   public:
   thread_adapter(void (*func)(void*, P &), void* param1, P &param2)
      : func_(func), param1_(param1) ,param2_(param2){ }
   void operator()() const { func_(param1_, param2_); }

   private:
   void (*func_)(void*, P &);
   void* param1_;
   P& param2_;
};

template <typename P>
struct data
{
   explicit data(int id, int msecs=0, int flags = 0, bool block = false)
      : m_id(id), m_value(-1), m_msecs(msecs), m_error(no_error), m_flags(flags), m_block(block)
   {}

   int            m_id;
   int            m_value;
   int            m_msecs;
   error_code_t   m_error;
   int            m_flags;
   bool           m_block;
};

int shared_val = 0;
static const unsigned BaseMs = 1000;

}  //namespace test {
}  //namespace interprocess {
}  //namespace boost {

#include <boost/interprocess/detail/config_end.hpp>

#endif   //#ifndef BOOST_INTERPROCESS_TEST_UTIL_HEADER