Realistic 3D camera system
3D camera system components
wince_thread.hpp
Go to the documentation of this file.
1 //
2 // detail/wince_thread.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_DETAIL_WINCE_THREAD_HPP
12 #define 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 "asio/detail/config.hpp"
19 
20 #if defined(ASIO_WINDOWS) && defined(UNDER_CE)
21 
22 #include <memory>
26 #include "asio/error.hpp"
27 
29 
30 namespace asio {
31 namespace detail {
32 
33 DWORD WINAPI wince_thread_function(LPVOID arg);
34 
35 class wince_thread
36  : private noncopyable
37 {
38 public:
39  // Constructor.
40  template <typename Function>
41  wince_thread(Function f, unsigned int = 0)
42  {
43  std::auto_ptr<func_base> arg(new func<Function>(f));
44  DWORD thread_id = 0;
45  thread_ = ::CreateThread(0, 0, wince_thread_function,
46  arg.get(), 0, &thread_id);
47  if (!thread_)
48  {
49  DWORD last_error = ::GetLastError();
50  asio::error_code ec(last_error,
52  asio::detail::throw_error(ec, "thread");
53  }
54  arg.release();
55  }
56 
57  // Destructor.
58  ~wince_thread()
59  {
60  ::CloseHandle(thread_);
61  }
62 
63  // Wait for the thread to exit.
64  void join()
65  {
66  ::WaitForSingleObject(thread_, INFINITE);
67  }
68 
69 private:
70  friend DWORD WINAPI wince_thread_function(LPVOID arg);
71 
72  class func_base
73  {
74  public:
75  virtual ~func_base() {}
76  virtual void run() = 0;
77  };
78 
79  template <typename Function>
80  class func
81  : public func_base
82  {
83  public:
84  func(Function f)
85  : f_(f)
86  {
87  }
88 
89  virtual void run()
90  {
91  f_();
92  }
93 
94  private:
95  Function f_;
96  };
97 
98  ::HANDLE thread_;
99 };
100 
101 inline DWORD WINAPI wince_thread_function(LPVOID arg)
102 {
103  std::auto_ptr<wince_thread::func_base> func(
104  static_cast<wince_thread::func_base*>(arg));
105  func->run();
106  return 0;
107 }
108 
109 } // namespace detail
110 } // namespace asio
111 
113 
114 #endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
115 
116 #endif // ASIO_DETAIL_WINCE_THREAD_HPP
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
const asio::error_category & get_system_category()
Definition: error.hpp:226
Class to represent an error code value.
Definition: error_code.hpp:80