5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef ASIO_DETAIL_WINCE_THREAD_HPP
12
#define ASIO_DETAIL_WINCE_THREAD_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
22
#include "asio/detail/pop_options.hpp"
24
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
26
#include "asio/error.hpp"
27
#include "asio/system_error.hpp"
28
#include "asio/detail/noncopyable.hpp"
29
#include "asio/detail/socket_types.hpp"
31
#include "asio/detail/push_options.hpp"
32
#include <boost/throw_exception.hpp>
34
#include "asio/detail/pop_options.hpp"
39
DWORD WINAPI wince_thread_function(LPVOID arg);
45
// The purpose of the thread.
46
enum purpose { internal, external };
49
template <typename Function>
50
wince_thread(Function f, purpose = internal)
52
std::auto_ptr<func_base> arg(new func<Function>(f));
54
thread_ = ::CreateThread(0, 0, wince_thread_function,
55
arg.get(), 0, &thread_id);
58
DWORD last_error = ::GetLastError();
60
asio::error_code(last_error,
61
asio::error::get_system_category()),
63
boost::throw_exception(e);
71
::CloseHandle(thread_);
74
// Wait for the thread to exit.
77
::WaitForSingleObject(thread_, INFINITE);
81
friend DWORD WINAPI wince_thread_function(LPVOID arg);
86
virtual ~func_base() {}
87
virtual void run() = 0;
90
template <typename Function>
112
inline DWORD WINAPI wince_thread_function(LPVOID arg)
114
std::auto_ptr<wince_thread::func_base> func(
115
static_cast<wince_thread::func_base*>(arg));
120
} // namespace detail
123
#endif // defined(BOOST_WINDOWS) && defined(UNDER_CE)
125
#include "asio/detail/pop_options.hpp"
127
#endif // ASIO_DETAIL_WINCE_THREAD_HPP