c++ poco Event 源码剖析

1.概述

    An Event is a synchronization object that allows one thread to signal one or more other threads that a certain event has happened.Usually, one thread signals an event,while one or more other threads waitfor an event to become signalled.

  事件是Poco提供的一种线程间通信方式,可用作线程间超时判断或者其他用途。

2.类图

这里写图片描述
  Event类私有继承于EventImpl类。线程锁、条件变量和状态布尔量都是EventImpl的私有成员,系统调用应用于EventImpl的函数成员。

3.接口解析

3.1构造函数
Event::Event(bool autoReset): EventImpl(autoReset)
{
}
EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
{
#if defined(POCO_VXWORKS)
    std::memset(&_mutex, 0, sizeof(_mutex));
#endif

    if (pthread_mutex_init(&_mutex, NULL))
        throw SystemException("cannot create event (mutex)");

#if defined(POCO_HAVE_MONOTONIC_PTHREAD_COND_TIMEDWAIT)
    pthread_condattr_t attr;
    if (pthread_condattr_init(&attr))
    {
        pthread_mutex_destroy(&_mutex);
        throw<
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值