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
8 #include <boost/thread/detail/config.hpp>
9 #include <boost/intrusive_ptr.hpp>
10 #include <boost/thread/thread_time.hpp>
11 #include "thread_primitives.hpp"
12 #include "thread_heap_alloc.hpp"
14 #include <boost/config/abi_prefix.hpp>
20 struct thread_exit_callback_node;
23 struct thread_data_base;
24 void intrusive_ptr_add_ref(thread_data_base * p);
25 void intrusive_ptr_release(thread_data_base * p);
27 struct thread_data_base
30 detail::win32::handle_manager thread_handle;
31 detail::win32::handle_manager interruption_handle;
32 boost::detail::thread_exit_callback_node* thread_exit_callbacks;
33 boost::detail::tss_data_node* tss_data;
34 bool interruption_enabled;
38 count(0),thread_handle(detail::win32::invalid_handle_value),
39 interruption_handle(create_anonymous_event(detail::win32::manual_reset_event,detail::win32::event_initially_reset)),
40 thread_exit_callbacks(0),tss_data(0),
41 interruption_enabled(true),
44 virtual ~thread_data_base()
47 friend void intrusive_ptr_add_ref(thread_data_base * p)
49 BOOST_INTERLOCKED_INCREMENT(&p->count);
52 friend void intrusive_ptr_release(thread_data_base * p)
54 if(!BOOST_INTERLOCKED_DECREMENT(&p->count))
56 detail::heap_delete(p);
62 BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0);
65 typedef detail::win32::handle native_handle_type;
70 typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
75 uintmax_t milliseconds;
77 boost::system_time abs_time;
79 static unsigned long const max_non_infinite_wait=0xfffffffe;
81 timeout(uintmax_t milliseconds_):
82 start(win32::GetTickCount()),
83 milliseconds(milliseconds_),
85 abs_time(boost::get_system_time())
88 timeout(boost::system_time const& abs_time_):
89 start(win32::GetTickCount()),
98 unsigned long milliseconds;
100 remaining_time(uintmax_t remaining):
101 more(remaining>max_non_infinite_wait),
102 milliseconds(more?max_non_infinite_wait:(unsigned long)remaining)
106 remaining_time remaining_milliseconds() const
110 return remaining_time(win32::infinite);
114 unsigned long const now=win32::GetTickCount();
115 unsigned long const elapsed=now-start;
116 return remaining_time((elapsed<milliseconds)?(milliseconds-elapsed):0);
120 system_time const now=get_system_time();
123 return remaining_time(0);
125 return remaining_time((abs_time-now).total_milliseconds()+1);
129 bool is_sentinel() const
131 return milliseconds==~uintmax_t(0);
135 static timeout sentinel()
137 return timeout(sentinel_type());
143 explicit timeout(sentinel_type):
144 start(0),milliseconds(~uintmax_t(0)),relative(true)
148 inline uintmax_t pin_to_zero(intmax_t value)
150 return (value<0)?0u:(uintmax_t)value;
154 namespace this_thread
156 void BOOST_THREAD_DECL yield();
158 bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time);
159 inline void interruptible_wait(uintmax_t milliseconds)
161 interruptible_wait(detail::win32::invalid_handle_value,milliseconds);
163 inline void interruptible_wait(system_time const& abs_time)
165 interruptible_wait(detail::win32::invalid_handle_value,abs_time);
168 template<typename TimeDuration>
169 inline void sleep(TimeDuration const& rel_time)
171 interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
173 inline void sleep(system_time const& abs_time)
175 interruptible_wait(abs_time);
181 #include <boost/config/abi_suffix.hpp>