2019-07-27 22:44:32 +08:00
|
|
|
|
#pragma once
|
2018-11-30 14:38:22 +08:00
|
|
|
|
#include "fiber_cpp_define.hpp"
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
|
|
2018-12-01 12:04:36 +08:00
|
|
|
|
struct ACL_FIBER_COND;
|
2018-11-30 14:38:22 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class fiber_event;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 可用在协程之间,线程之间,协程与线程之间的条件变量
|
2018-11-30 14:38:22 +08:00
|
|
|
|
*/
|
2019-05-09 13:57:51 +08:00
|
|
|
|
class FIBER_CPP_API fiber_cond : public noncopyable
|
2018-11-30 14:38:22 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
fiber_cond(void);
|
|
|
|
|
~fiber_cond(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 等待条件变量事件被触发
|
2018-11-30 14:38:22 +08:00
|
|
|
|
* @param event {fiber_event&}
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @param timeout {int} 超时等待时间(毫秒)
|
|
|
|
|
* @return {bool} 成功时返回 true,否则返回 false 表示超时
|
2018-11-30 14:38:22 +08:00
|
|
|
|
*/
|
2018-12-07 13:50:42 +08:00
|
|
|
|
bool wait(fiber_event& event, int timeout = -1);
|
2018-11-30 14:38:22 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 唤醒在条件变量上的等待者,如果没有等待者则直接返回,运行行为和
|
|
|
|
|
* 线程条件变量类似
|
|
|
|
|
* @return {bool} 成功返回 true,否则返回 false 表示失败
|
2018-11-30 14:38:22 +08:00
|
|
|
|
*/
|
|
|
|
|
bool notify(void);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 返回 C 版本的条件变量对象
|
2018-11-30 14:38:22 +08:00
|
|
|
|
* @return {ACL_FIBER_COND*}
|
|
|
|
|
*/
|
|
|
|
|
ACL_FIBER_COND* get_cond(void) const
|
|
|
|
|
{
|
|
|
|
|
return cond_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ACL_FIBER_COND* cond_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|