x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
thread.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\thread\win32\thread.hpp
旋转
特效
属性
历史版本
#ifndef BOOST_THREAD_THREAD_WIN32_HPP #define BOOST_THREAD_THREAD_WIN32_HPP // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // (C) Copyright 2007 Anthony Williams #include
#include
#include
#include
#include
#include
#include
#include "thread_primitives.hpp" #include "thread_heap_alloc.hpp" #include
#include
#include
#include
#include
#include
#include
#include
#ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4251) #endif namespace boost { class thread_interrupted {}; namespace detail { struct thread_exit_callback_node; struct tss_data_node; struct thread_data_base { long count; detail::win32::handle_manager thread_handle; detail::win32::handle_manager interruption_handle; boost::detail::thread_exit_callback_node* thread_exit_callbacks; boost::detail::tss_data_node* tss_data; bool interruption_enabled; unsigned id; thread_data_base(): count(0),thread_handle(detail::win32::invalid_handle_value), interruption_handle(create_anonymous_event(detail::win32::manual_reset_event,detail::win32::event_initially_reset)), thread_exit_callbacks(0),tss_data(0), interruption_enabled(true), id(0) {} virtual ~thread_data_base() {} friend void intrusive_ptr_add_ref(thread_data_base * p) { BOOST_INTERLOCKED_INCREMENT(&p->count); } friend void intrusive_ptr_release(thread_data_base * p) { if(!BOOST_INTERLOCKED_DECREMENT(&p->count)) { detail::heap_delete(p); } } void interrupt() { BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0); } virtual void run()=0; }; typedef boost::intrusive_ptr
thread_data_ptr; struct timeout { unsigned long start; uintmax_t milliseconds; bool relative; boost::system_time abs_time; static unsigned long const max_non_infinite_wait=0xfffffffe; timeout(uintmax_t milliseconds_): start(win32::GetTickCount()), milliseconds(milliseconds_), relative(true), abs_time(boost::get_system_time()) {} timeout(boost::system_time const& abs_time_): start(win32::GetTickCount()), milliseconds(0), relative(false), abs_time(abs_time_) {} struct remaining_time { bool more; unsigned long milliseconds; remaining_time(uintmax_t remaining): more(remaining>max_non_infinite_wait), milliseconds(more?max_non_infinite_wait:(unsigned long)remaining) {} }; remaining_time remaining_milliseconds() const { if(is_sentinel()) { return remaining_time(win32::infinite); } else if(relative) { unsigned long const now=win32::GetTickCount(); unsigned long const elapsed=now-start; return remaining_time((elapsed
struct thread_data: detail::thread_data_base { F f; thread_data(F f_): f(f_) {} thread_data(detail::thread_move_t
f_): f(f_) {} void run() { f(); } }; mutable boost::mutex thread_info_mutex; detail::thread_data_ptr thread_info; static unsigned __stdcall thread_start_function(void* param); void start_thread(); explicit thread(detail::thread_data_ptr data); detail::thread_data_ptr get_thread_info() const; public: thread(); ~thread(); template
explicit thread(F f): thread_info(detail::heap_new
>(f)) { start_thread(); } template
thread(detail::thread_move_t
f): thread_info(detail::heap_new
>(f)) { start_thread(); } thread(detail::thread_move_t
x); thread& operator=(detail::thread_move_t
x); operator detail::thread_move_t
(); detail::thread_move_t
move(); void swap(thread& x); class id; id get_id() const; bool joinable() const; void join(); bool timed_join(const system_time& wait_until); template
inline bool timed_join(TimeDuration const& rel_time) { return timed_join(get_system_time()+rel_time); } void detach(); static unsigned hardware_concurrency(); typedef detail::win32::handle native_handle_type; native_handle_type native_handle(); // backwards compatibility bool operator==(const thread& other) const; bool operator!=(const thread& other) const; static void yield(); static void sleep(const system_time& xt); // extensions void interrupt(); bool interruption_requested() const; }; inline detail::thread_move_t
move(thread& x) { return x.move(); } inline detail::thread_move_t
move(detail::thread_move_t
x) { return x; } template
struct thread::thread_data
>: detail::thread_data_base { F& f; thread_data(boost::reference_wrapper
f_): f(f_) {} void run() { f(); } }; namespace this_thread { class BOOST_THREAD_DECL disable_interruption { disable_interruption(const disable_interruption&); disable_interruption& operator=(const disable_interruption&); bool interruption_was_enabled; friend class restore_interruption; public: disable_interruption(); ~disable_interruption(); }; class BOOST_THREAD_DECL restore_interruption { restore_interruption(const restore_interruption&); restore_interruption& operator=(const restore_interruption&); public: explicit restore_interruption(disable_interruption& d); ~restore_interruption(); }; thread::id BOOST_THREAD_DECL get_id(); bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time); inline bool interruptible_wait(unsigned long milliseconds) { return interruptible_wait(detail::win32::invalid_handle_value,milliseconds); } void BOOST_THREAD_DECL interruption_point(); bool BOOST_THREAD_DECL interruption_enabled(); bool BOOST_THREAD_DECL interruption_requested(); void BOOST_THREAD_DECL yield(); template
void sleep(TimeDuration const& rel_time) { interruptible_wait(static_cast
(rel_time.total_milliseconds())); } } class thread::id { private: detail::thread_data_ptr thread_data; id(detail::thread_data_ptr thread_data_): thread_data(thread_data_) {} friend class thread; friend id this_thread::get_id(); public: id(): thread_data(0) {} bool operator==(const id& y) const { return thread_data==y.thread_data; } bool operator!=(const id& y) const { return thread_data!=y.thread_data; } bool operator<(const id& y) const { return thread_data
(const id& y) const { return y.thread_data
=(const id& y) const { return !(thread_data
friend std::basic_ostream
& operator<<(std::basic_ostream
& os, const id& x) { if(x.thread_data) { return os<
interrupt(); } } }; inline bool thread::operator==(const thread& other) const { return get_id()==other.get_id(); } inline bool thread::operator!=(const thread& other) const { return get_id()!=other.get_id(); } namespace detail { struct thread_exit_function_base { virtual ~thread_exit_function_base() {} virtual void operator()() const=0; }; template
struct thread_exit_function: thread_exit_function_base { F f; thread_exit_function(F f_): f(f_) {} void operator()() const { f(); } }; void add_thread_exit_function(thread_exit_function_base*); } namespace this_thread { template
void at_thread_exit(F f) { detail::thread_exit_function_base* const thread_exit_func=detail::heap_new
>(f); detail::add_thread_exit_function(thread_exit_func); } } class thread_group: private noncopyable { public: ~thread_group() { for(std::list
::iterator it=threads.begin(),end=threads.end(); it!=end; ++it) { delete *it; } } template
thread* create_thread(F threadfunc) { boost::lock_guard
guard(m); std::auto_ptr
new_thread(new thread(threadfunc)); threads.push_back(new_thread.get()); return new_thread.release(); } void add_thread(thread* thrd) { if(thrd) { boost::lock_guard
guard(m); threads.push_back(thrd); } } void remove_thread(thread* thrd) { boost::lock_guard
guard(m); std::list
::iterator const it=std::find(threads.begin(),threads.end(),thrd); if(it!=threads.end()) { threads.erase(it); } } void join_all() { boost::lock_guard
guard(m); for(std::list
::iterator it=threads.begin(),end=threads.end(); it!=end; ++it) { (*it)->join(); } } void interrupt_all() { boost::lock_guard
guard(m); for(std::list
::iterator it=threads.begin(),end=threads.end(); it!=end; ++it) { (*it)->interrupt(); } } size_t size() const { boost::lock_guard
guard(m); return threads.size(); } private: std::list
threads; mutable mutex m; }; } #ifdef BOOST_MSVC #pragma warning(pop) #endif #endif
thread.hpp
网页地址
文件地址
上一页
9/12
下一页
下载
( 14 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.