Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/asio/detail/wince_thread.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // | |
2 // detail/wince_thread.hpp | |
3 // ~~~~~~~~~~~~~~~~~~~~~~~ | |
4 // | |
5 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) | |
6 // | |
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 // | |
10 | |
11 #ifndef BOOST_ASIO_DETAIL_WINCE_THREAD_HPP | |
12 #define BOOST_ASIO_DETAIL_WINCE_THREAD_HPP | |
13 | |
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
15 # pragma once | |
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) | |
17 | |
18 #include <boost/asio/detail/config.hpp> | |
19 | |
20 #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) | |
21 | |
22 #include <memory> | |
23 #include <boost/asio/detail/noncopyable.hpp> | |
24 #include <boost/asio/detail/socket_types.hpp> | |
25 #include <boost/asio/detail/throw_error.hpp> | |
26 #include <boost/asio/error.hpp> | |
27 | |
28 #include <boost/asio/detail/push_options.hpp> | |
29 | |
30 namespace boost { | |
31 namespace asio { | |
32 namespace detail { | |
33 | |
34 DWORD WINAPI wince_thread_function(LPVOID arg); | |
35 | |
36 class wince_thread | |
37 : private noncopyable | |
38 { | |
39 public: | |
40 // Constructor. | |
41 template <typename Function> | |
42 wince_thread(Function f, unsigned int = 0) | |
43 { | |
44 std::auto_ptr<func_base> arg(new func<Function>(f)); | |
45 DWORD thread_id = 0; | |
46 thread_ = ::CreateThread(0, 0, wince_thread_function, | |
47 arg.get(), 0, &thread_id); | |
48 if (!thread_) | |
49 { | |
50 DWORD last_error = ::GetLastError(); | |
51 boost::system::error_code ec(last_error, | |
52 boost::asio::error::get_system_category()); | |
53 boost::asio::detail::throw_error(ec, "thread"); | |
54 } | |
55 arg.release(); | |
56 } | |
57 | |
58 // Destructor. | |
59 ~wince_thread() | |
60 { | |
61 ::CloseHandle(thread_); | |
62 } | |
63 | |
64 // Wait for the thread to exit. | |
65 void join() | |
66 { | |
67 ::WaitForSingleObject(thread_, INFINITE); | |
68 } | |
69 | |
70 private: | |
71 friend DWORD WINAPI wince_thread_function(LPVOID arg); | |
72 | |
73 class func_base | |
74 { | |
75 public: | |
76 virtual ~func_base() {} | |
77 virtual void run() = 0; | |
78 }; | |
79 | |
80 template <typename Function> | |
81 class func | |
82 : public func_base | |
83 { | |
84 public: | |
85 func(Function f) | |
86 : f_(f) | |
87 { | |
88 } | |
89 | |
90 virtual void run() | |
91 { | |
92 f_(); | |
93 } | |
94 | |
95 private: | |
96 Function f_; | |
97 }; | |
98 | |
99 ::HANDLE thread_; | |
100 }; | |
101 | |
102 inline DWORD WINAPI wince_thread_function(LPVOID arg) | |
103 { | |
104 std::auto_ptr<wince_thread::func_base> func( | |
105 static_cast<wince_thread::func_base*>(arg)); | |
106 func->run(); | |
107 return 0; | |
108 } | |
109 | |
110 } // namespace detail | |
111 } // namespace asio | |
112 } // namespace boost | |
113 | |
114 #include <boost/asio/detail/pop_options.hpp> | |
115 | |
116 #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) | |
117 | |
118 #endif // BOOST_ASIO_DETAIL_WINCE_THREAD_HPP |