x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
once.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\thread\win32\once.hpp
旋转
特效
属性
历史版本
#ifndef BOOST_THREAD_WIN32_ONCE_HPP #define BOOST_THREAD_WIN32_ONCE_HPP // once.hpp // // (C) Copyright 2005-7 Anthony Williams // (C) Copyright 2005 John Maddock // // 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) #include
#include
#include
#include
#include
#include
#include
#ifdef BOOST_NO_STDC_NAMESPACE namespace std { using ::memcpy; using ::ptrdiff_t; } #endif namespace boost { typedef long once_flag; #define BOOST_ONCE_INIT 0 namespace detail { struct win32_mutex_scoped_lock { void* const mutex_handle; explicit win32_mutex_scoped_lock(void* mutex_handle_): mutex_handle(mutex_handle_) { BOOST_VERIFY(!win32::WaitForSingleObject(mutex_handle,win32::infinite)); } ~win32_mutex_scoped_lock() { BOOST_VERIFY(win32::ReleaseMutex(mutex_handle)!=0); } private: void operator=(win32_mutex_scoped_lock&); }; #ifdef BOOST_NO_ANSI_APIS template
void int_to_string(I p, wchar_t* buf) { for(unsigned i=0; i < sizeof(I)*2; ++i,++buf) { *buf = L'A' + static_cast
((p >> (i*4)) & 0x0f); } *buf = 0; } #else template
void int_to_string(I p, char* buf) { for(unsigned i=0; i < sizeof(I)*2; ++i,++buf) { *buf = 'A' + static_cast
((p >> (i*4)) & 0x0f); } *buf = 0; } #endif // create a named mutex. It doesn't really matter what this name is // as long as it is unique both to this process, and to the address of "flag": inline void* create_once_mutex(void* flag_address) { #ifdef BOOST_NO_ANSI_APIS typedef wchar_t char_type; static const char_type fixed_mutex_name[]=L"{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag"; #else typedef char char_type; static const char_type fixed_mutex_name[]="{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag"; #endif unsigned const once_mutex_name_fixed_buffer_size=sizeof(fixed_mutex_name)/sizeof(char_type); unsigned const once_mutex_name_fixed_length=once_mutex_name_fixed_buffer_size-1; unsigned const once_mutex_name_length=once_mutex_name_fixed_buffer_size+sizeof(void*)*2+sizeof(unsigned long)*2; char_type mutex_name[once_mutex_name_length]; std::memcpy(mutex_name,fixed_mutex_name,sizeof(fixed_mutex_name)); BOOST_STATIC_ASSERT(sizeof(void*) == sizeof(std::ptrdiff_t)); detail::int_to_string(reinterpret_cast
(flag_address), mutex_name + once_mutex_name_fixed_length); detail::int_to_string(win32::GetCurrentProcessId(), mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2); #ifdef BOOST_NO_ANSI_APIS return win32::CreateMutexW(0, 0, mutex_name); #else return win32::CreateMutexA(0, 0, mutex_name); #endif } } template
void call_once(once_flag& flag,Function f) { // Try for a quick win: if the procedure has already been called // just skip through: long const function_complete_flag_value=0xc15730e2; if(::boost::detail::interlocked_read_acquire(&flag)!=function_complete_flag_value) { void* const mutex_handle(::boost::detail::create_once_mutex(&flag)); BOOST_ASSERT(mutex_handle); detail::win32::handle_manager const closer(mutex_handle); detail::win32_mutex_scoped_lock const lock(mutex_handle); if(flag!=function_complete_flag_value) { f(); BOOST_INTERLOCKED_EXCHANGE(&flag,function_complete_flag_value); } } } } #endif
once.hpp
网页地址
文件地址
上一页
6/12
下一页
下载
( 4 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.