做了一个不到200行的事件驱动库,基于c++11标准,header-only,跨平台。支持自定义事件,通过wake_up函数异步唤醒。写这个库的动机是想为之前自己写的日志库提供日志回滚机制。
基本介绍
a header-only event-driven library based on c++11.
一个基于c++11标准,仅需要头文件的事件驱动库:)。
使用方法
- 创建event_pool对象并申请一个线程做事件处理,在该线程中调用run函数。
//run the event_pool.
std::shared_ptr<event_pool> ev(new event_pool());
std::thread th([=]()->void {
ev->run();
});
- 创建event_handle和time_handle对象并设置id_,type_,回调函数func_,上下文args_(如果是time_handle则还要设置触发时间)等,push进event_pool对象。
//create time_handle.
std::shared_pt