当前位置: 首页 > news >正文

云存储能用来做网站吗券优惠网站如何做

云存储能用来做网站吗,券优惠网站如何做,合肥房产网站建设,做网站数据对电脑要求简介 asio设计static_mutex为了处理静态互斥量,即全局静态互斥量,其针对不同平台有不同的实现 静态互斥量static_mutex 通过条件编译对不同实现定义别名 #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_static_mutex static_mutex; # define BO…

简介

asio设计static_mutex为了处理静态互斥量,即全局静态互斥量,其针对不同平台有不同的实现

静态互斥量static_mutex

通过条件编译对不同实现定义别名

#if !defined(BOOST_ASIO_HAS_THREADS)
typedef null_static_mutex static_mutex;
# define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_NULL_STATIC_MUTEX_INIT
#elif defined(BOOST_ASIO_WINDOWS)
typedef win_static_mutex static_mutex;
# define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_WIN_STATIC_MUTEX_INIT
#elif defined(BOOST_ASIO_HAS_PTHREADS)
typedef posix_static_mutex static_mutex;
# define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_POSIX_STATIC_MUTEX_INIT
#elif defined(BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR)
typedef std_static_mutex static_mutex;
# define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_STD_STATIC_MUTEX_INIT
#endif

主要包含三个方法

  • init
  • lock
  • unlock

实现

windows平台实现

window平台为win_static_mutex,其定义为

struct win_static_mutex
{typedef boost::asio::detail::scoped_lock<win_static_mutex> scoped_lock;// Initialise the mutex.BOOST_ASIO_DECL void init();// Initialisation must be performed in a separate function to the "public"// init() function since the compiler does not support the use of structured// exceptions and C++ exceptions in the same function.BOOST_ASIO_DECL int do_init();// Lock the mutex.void lock(){::EnterCriticalSection(&crit_section_);}// Unlock the mutex.void unlock(){::LeaveCriticalSection(&crit_section_);}bool initialised_;::CRITICAL_SECTION crit_section_;
};

其初始化是通过创建有名互斥量,来保证只初始化一次

HANDLE mutex = ::CreateMutexW(0, TRUE, mutex_name);
//说明另一个线程已经创建互斥量,等待另一线程初始化完释放互斥量。因为创建成功的线程持有
if (last_error == ERROR_ALREADY_EXISTS)   ::WaitForSingleObject(mutex, INFINITE);
//初始化临界区
#if defined(__MINGW32__)// Not sure if MinGW supports structured exception handling, so for now// we'll just call the Windows API and hope.
# if defined(UNDER_CE)::InitializeCriticalSection(&crit_section_);
# elseif (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000)){last_error = ::GetLastError();::ReleaseMutex(mutex);::CloseHandle(mutex);return last_error;}
# endif
#else__try{
# if defined(UNDER_CE)::InitializeCriticalSection(&crit_section_);
# elseif (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000)){last_error = ::GetLastError();::ReleaseMutex(mutex);::CloseHandle(mutex);return last_error;}
# endif}__except(GetExceptionCode() == STATUS_NO_MEMORY? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH){::ReleaseMutex(mutex);::CloseHandle(mutex);return ERROR_OUTOFMEMORY;}
#endifinitialised_ = true;::ReleaseMutex(mutex);::CloseHandle(mutex);

同时在类中定义有scoped_lock,用于互斥量的RAII
其静态初始化为

#if defined(UNDER_CE)
# define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } }
#else // defined(UNDER_CE)
# define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } }
#endif // defined(UNDER_CE)

linux平台实现

实现是posix_static_mutex,其定义为

struct posix_static_mutex
{typedef boost::asio::detail::scoped_lock<posix_static_mutex> scoped_lock;// Initialise the mutex.void init(){// Nothing to do.}// Lock the mutex.void lock(){(void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL.}// Unlock the mutex.void unlock(){(void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL.}::pthread_mutex_t mutex_;
};
//初始化
#define BOOST_ASIO_POSIX_STATIC_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER }

std标准实现

实现类为std_static_mutex,定义为

class std_static_mutex: private noncopyable
{
public:typedef boost::asio::detail::scoped_lock<std_static_mutex> scoped_lock;// Constructor.std_static_mutex(int){}// Destructor.~std_static_mutex(){}// Initialise the mutex.void init(){// Nothing to do.}// Lock the mutex.void lock(){mutex_.lock();}// Unlock the mutex.void unlock(){mutex_.unlock();}private:friend class std_event;std::mutex mutex_;
};//初始化
#define BOOST_ASIO_STD_STATIC_MUTEX_INIT 0

空实现

实现类为null_static_mutex,定义为

struct null_static_mutex
{typedef boost::asio::detail::scoped_lock<null_static_mutex> scoped_lock;// Initialise the mutex.void init(){}// Lock the mutex.void lock(){}// Unlock the mutex.void unlock(){}int unused_;
};
//初始化
#define BOOST_ASIO_NULL_STATIC_MUTEX_INIT { 0 }
http://www.dtcms.com/a/586994.html

相关文章:

  • 自己做网站怎样挣钱当面付 wordpress
  • SIDI模型:压力诱导的审慎到直觉决策模拟
  • 大连网站制作网站珠海网站制作计划
  • 长沙企业网站建设优度创建iis网站
  • 咨询类网站建设个人怎样做旅游网站
  • RHCE Day3 DNS服务器
  • Android15 拓展安全策略SEPOLICY
  • 有创意的网站开发wordpress免插件生成地图
  • 百度如何创建网站深圳市建筑人才网
  • 耐克运动鞋网站建设规划书框架dedecms英文外贸网站企业模板
  • Java_Collections工具类
  • 重庆做网站letide杭州网站制作外包
  • seo品牌优化百度资源网站推广关键词排名网站开发课程设计
  • 专业网站建设市场金蝶直播
  • 网站建设可行性报告提供网站制作公司报价
  • 饲料网站建设 中企动力WordPress百度智能小程序
  • 安徽城乡建设厅官方网站电商一共有什么平台
  • 网站设计网址做银行设计有好的网站参考吗
  • 渭南企业网站建设wordpress 主题 api
  • 网站设计和建设自考题做淘宝的网站有哪些内容吗
  • WiFi密码B破器-密码查看器、可跑字典-免费无广
  • 触觉智能IPC8815迷你工控机规格书,详细参数配置,适用AGV/机器人等领域
  • 网站域名去哪里备案营销型网站建设范文
  • 网站代码特效广告使用下载的整站asp源代码建设自己的私人网站需要注意哪些
  • 比较初始位置对结构图像的影响
  • 做网站 怎么备案如何用自己的电脑做网站空间
  • 网站建设源程序软件开发外包服务
  • 小程序样式模板镇江网站关键词优化预订
  • 手撕容器string(了解底层)2
  • 阿里巴巴国际网站做网站可以吗网站域名注册信息查询