~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/boost/thread/win32/thread_data.hpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef BOOST_THREAD_PTHREAD_THREAD_DATA_HPP
2
 
#define BOOST_THREAD_PTHREAD_THREAD_DATA_HPP
3
 
// Distributed under the Boost Software License, Version 1.0. (See
4
 
// accompanying file LICENSE_1_0.txt or copy at
5
 
// http://www.boost.org/LICENSE_1_0.txt)
6
 
// (C) Copyright 2008 Anthony Williams
7
 
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
8
 
 
9
 
#include <boost/thread/detail/config.hpp>
10
 
#include <boost/thread/thread_time.hpp>
11
 
#include <boost/thread/win32/thread_primitives.hpp>
12
 
#include <boost/thread/win32/thread_heap_alloc.hpp>
13
 
 
14
 
#include <boost/intrusive_ptr.hpp>
15
 
#ifdef BOOST_THREAD_USES_CHRONO
16
 
#include <boost/chrono/system_clocks.hpp>
17
 
#endif
18
 
 
19
 
#include <map>
20
 
#include <vector>
21
 
#include <utility>
22
 
 
23
 
#include <boost/config/abi_prefix.hpp>
24
 
 
25
 
#ifdef BOOST_MSVC
26
 
#pragma warning(push)
27
 
#pragma warning(disable:4251)
28
 
#endif
29
 
 
30
 
namespace boost
31
 
{
32
 
  class condition_variable;
33
 
  class mutex;
34
 
 
35
 
  class thread_attributes {
36
 
  public:
37
 
      thread_attributes() BOOST_NOEXCEPT {
38
 
        val_.stack_size = 0;
39
 
        //val_.lpThreadAttributes=0;
40
 
      }
41
 
      ~thread_attributes() {
42
 
      }
43
 
      // stack size
44
 
      void set_stack_size(std::size_t size) BOOST_NOEXCEPT {
45
 
        val_.stack_size = size;
46
 
      }
47
 
 
48
 
      std::size_t get_stack_size() const BOOST_NOEXCEPT {
49
 
          return val_.stack_size;
50
 
      }
51
 
 
52
 
      //void set_security(LPSECURITY_ATTRIBUTES lpThreadAttributes)
53
 
      //{
54
 
      //  val_.lpThreadAttributes=lpThreadAttributes;
55
 
      //}
56
 
      //LPSECURITY_ATTRIBUTES get_security()
57
 
      //{
58
 
      //  return val_.lpThreadAttributes;
59
 
      //}
60
 
 
61
 
      struct win_attrs {
62
 
        std::size_t stack_size;
63
 
        //LPSECURITY_ATTRIBUTES lpThreadAttributes;
64
 
      };
65
 
      typedef win_attrs native_handle_type;
66
 
      native_handle_type* native_handle() {return &val_;}
67
 
      const native_handle_type* native_handle() const {return &val_;}
68
 
 
69
 
  private:
70
 
      win_attrs val_;
71
 
  };
72
 
 
73
 
    namespace detail
74
 
    {
75
 
        struct shared_state_base;
76
 
        struct tss_cleanup_function;
77
 
        struct thread_exit_callback_node;
78
 
        struct tss_data_node
79
 
        {
80
 
            boost::shared_ptr<boost::detail::tss_cleanup_function> func;
81
 
            void* value;
82
 
 
83
 
            tss_data_node(boost::shared_ptr<boost::detail::tss_cleanup_function> func_,
84
 
                          void* value_):
85
 
                func(func_),value(value_)
86
 
            {}
87
 
        };
88
 
 
89
 
        struct thread_data_base;
90
 
        void intrusive_ptr_add_ref(thread_data_base * p);
91
 
        void intrusive_ptr_release(thread_data_base * p);
92
 
 
93
 
        struct BOOST_THREAD_DECL thread_data_base
94
 
        {
95
 
            long count;
96
 
            detail::win32::handle_manager thread_handle;
97
 
            boost::detail::thread_exit_callback_node* thread_exit_callbacks;
98
 
            std::map<void const*,boost::detail::tss_data_node> tss_data;
99
 
            unsigned id;
100
 
            typedef std::vector<std::pair<condition_variable*, mutex*>
101
 
            //, hidden_allocator<std::pair<condition_variable*, mutex*> >
102
 
            > notify_list_t;
103
 
            notify_list_t notify;
104
 
 
105
 
            typedef std::vector<shared_ptr<shared_state_base> > async_states_t;
106
 
            async_states_t async_states_;
107
 
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
108
 
            // These data must be at the end so that the access to the other fields doesn't change
109
 
            // when BOOST_THREAD_PROVIDES_INTERRUPTIONS is defined
110
 
            // Another option is to have them always
111
 
            detail::win32::handle_manager interruption_handle;
112
 
            bool interruption_enabled;
113
 
//#endif
114
 
 
115
 
            thread_data_base():
116
 
                count(0),thread_handle(detail::win32::invalid_handle_value),
117
 
                thread_exit_callbacks(0),tss_data(),
118
 
                id(0),
119
 
                notify(),
120
 
                async_states_()
121
 
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
122
 
                , interruption_handle(create_anonymous_event(detail::win32::manual_reset_event,detail::win32::event_initially_reset))
123
 
                , interruption_enabled(true)
124
 
//#endif
125
 
            {}
126
 
            virtual ~thread_data_base();
127
 
 
128
 
            friend void intrusive_ptr_add_ref(thread_data_base * p)
129
 
            {
130
 
                BOOST_INTERLOCKED_INCREMENT(&p->count);
131
 
            }
132
 
 
133
 
            friend void intrusive_ptr_release(thread_data_base * p)
134
 
            {
135
 
                if(!BOOST_INTERLOCKED_DECREMENT(&p->count))
136
 
                {
137
 
                    detail::heap_delete(p);
138
 
                }
139
 
            }
140
 
 
141
 
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
142
 
            void interrupt()
143
 
            {
144
 
                BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0);
145
 
            }
146
 
#endif
147
 
            typedef detail::win32::handle native_handle_type;
148
 
 
149
 
            virtual void run()=0;
150
 
 
151
 
            virtual void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
152
 
            {
153
 
              notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
154
 
            }
155
 
 
156
 
            void make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
157
 
            {
158
 
              async_states_.push_back(as);
159
 
            }
160
 
 
161
 
        };
162
 
        BOOST_THREAD_DECL thread_data_base* get_current_thread_data();
163
 
 
164
 
        typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
165
 
 
166
 
        struct BOOST_SYMBOL_VISIBLE timeout
167
 
        {
168
 
            win32::ticks_type start;
169
 
            uintmax_t milliseconds;
170
 
            bool relative;
171
 
            boost::system_time abs_time;
172
 
 
173
 
            static unsigned long const max_non_infinite_wait=0xfffffffe;
174
 
 
175
 
            timeout(uintmax_t milliseconds_):
176
 
                start(win32::GetTickCount64()),
177
 
                milliseconds(milliseconds_),
178
 
                relative(true),
179
 
                abs_time(boost::get_system_time())
180
 
            {}
181
 
 
182
 
            timeout(boost::system_time const& abs_time_):
183
 
                start(win32::GetTickCount64()),
184
 
                milliseconds(0),
185
 
                relative(false),
186
 
                abs_time(abs_time_)
187
 
            {}
188
 
 
189
 
            struct BOOST_SYMBOL_VISIBLE remaining_time
190
 
            {
191
 
                bool more;
192
 
                unsigned long milliseconds;
193
 
 
194
 
                remaining_time(uintmax_t remaining):
195
 
                    more(remaining>max_non_infinite_wait),
196
 
                    milliseconds(more?max_non_infinite_wait:(unsigned long)remaining)
197
 
                {}
198
 
            };
199
 
 
200
 
            remaining_time remaining_milliseconds() const
201
 
            {
202
 
                if(is_sentinel())
203
 
                {
204
 
                    return remaining_time(win32::infinite);
205
 
                }
206
 
                else if(relative)
207
 
                {
208
 
                    win32::ticks_type const now=win32::GetTickCount64();
209
 
                    win32::ticks_type const elapsed=now-start;
210
 
                    return remaining_time((elapsed<milliseconds)?(milliseconds-elapsed):0);
211
 
                }
212
 
                else
213
 
                {
214
 
                    system_time const now=get_system_time();
215
 
                    if(abs_time<=now)
216
 
                    {
217
 
                        return remaining_time(0);
218
 
                    }
219
 
                    return remaining_time((abs_time-now).total_milliseconds()+1);
220
 
                }
221
 
            }
222
 
 
223
 
            bool is_sentinel() const
224
 
            {
225
 
                return milliseconds==~uintmax_t(0);
226
 
            }
227
 
 
228
 
 
229
 
            static timeout sentinel()
230
 
            {
231
 
                return timeout(sentinel_type());
232
 
            }
233
 
        private:
234
 
            struct sentinel_type
235
 
            {};
236
 
 
237
 
            explicit timeout(sentinel_type):
238
 
                start(0),milliseconds(~uintmax_t(0)),relative(true)
239
 
            {}
240
 
        };
241
 
 
242
 
        inline uintmax_t pin_to_zero(intmax_t value)
243
 
        {
244
 
            return (value<0)?0u:(uintmax_t)value;
245
 
        }
246
 
    }
247
 
 
248
 
    namespace this_thread
249
 
    {
250
 
        void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT;
251
 
 
252
 
        bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time);
253
 
        inline void interruptible_wait(uintmax_t milliseconds)
254
 
        {
255
 
            interruptible_wait(detail::win32::invalid_handle_value,milliseconds);
256
 
        }
257
 
        inline BOOST_SYMBOL_VISIBLE void interruptible_wait(system_time const& abs_time)
258
 
        {
259
 
            interruptible_wait(detail::win32::invalid_handle_value,abs_time);
260
 
        }
261
 
        template<typename TimeDuration>
262
 
        inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
263
 
        {
264
 
            interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
265
 
        }
266
 
        inline BOOST_SYMBOL_VISIBLE void sleep(system_time const& abs_time)
267
 
        {
268
 
            interruptible_wait(abs_time);
269
 
        }
270
 
#ifdef BOOST_THREAD_USES_CHRONO
271
 
        inline void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
272
 
        {
273
 
          interruptible_wait(chrono::duration_cast<chrono::milliseconds>(ns).count());
274
 
        }
275
 
#endif
276
 
    }
277
 
 
278
 
}
279
 
 
280
 
#ifdef BOOST_MSVC
281
 
#pragma warning(pop)
282
 
#endif
283
 
 
284
 
#include <boost/config/abi_suffix.hpp>
285
 
 
286
 
#endif