x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
basic_recursive_mutex.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\thread\win32\basic_recursive_mutex.hpp
旋转
特效
属性
历史版本
#ifndef BOOST_BASIC_RECURSIVE_MUTEX_WIN32_HPP #define BOOST_BASIC_RECURSIVE_MUTEX_WIN32_HPP // basic_recursive_mutex.hpp // // (C) Copyright 2006-7 Anthony Williams // // 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 "thread_primitives.hpp" #include "basic_timed_mutex.hpp" namespace boost { namespace detail { template
struct basic_recursive_mutex_impl { long recursion_count; long locking_thread_id; underlying_mutex_type mutex; void initialize() { recursion_count=0; locking_thread_id=0; mutex.initialize(); } void destroy() { mutex.destroy(); } bool try_lock() { long const current_thread_id=win32::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_basic_lock(current_thread_id); } void lock() { long const current_thread_id=win32::GetCurrentThreadId(); if(!try_recursive_lock(current_thread_id)) { mutex.lock(); BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id); recursion_count=1; } } bool timed_lock(::boost::system_time const& target) { long const current_thread_id=win32::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target); } template
bool timed_lock(Duration const& timeout) { return timed_lock(get_system_time()+timeout); } long get_active_count() { return mutex.get_active_count(); } void unlock() { if(!--recursion_count) { BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,0); mutex.unlock(); } } bool locked() { return mutex.locked(); } private: bool try_recursive_lock(long current_thread_id) { if(::boost::detail::interlocked_read_acquire(&locking_thread_id)==current_thread_id) { ++recursion_count; return true; } return false; } bool try_basic_lock(long current_thread_id) { if(mutex.try_lock()) { BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id); recursion_count=1; return true; } return false; } bool try_timed_lock(long current_thread_id,::boost::system_time const& target) { if(mutex.timed_lock(target)) { BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id); recursion_count=1; return true; } return false; } }; typedef basic_recursive_mutex_impl
basic_recursive_mutex; typedef basic_recursive_mutex_impl
basic_recursive_timed_mutex; } } #define BOOST_BASIC_RECURSIVE_MUTEX_INITIALIZER {0} #endif
basic_recursive_mutex.hpp
网页地址
文件地址
上一页 1/12
下一页
下载
( 3 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.