12a18e699SShuo Chen// copied from muduo/net/tests/TimerQueue_unittest.cc 22a18e699SShuo Chen 32a18e699SShuo Chen#include "EventLoop.h" 42a18e699SShuo Chen 52a18e699SShuo Chen#include <boost/bind.hpp> 62a18e699SShuo Chen 72a18e699SShuo Chen#include <stdio.h> 82a18e699SShuo Chen 92a18e699SShuo Chenint cnt = 0; 102a18e699SShuo Chenmuduo::EventLoop* g_loop; 112a18e699SShuo Chen 122a18e699SShuo Chenvoid printTid() 132a18e699SShuo Chen{ 142a18e699SShuo Chen printf("pid = %d, tid = %d\n", getpid(), muduo::CurrentThread::tid()); 152a18e699SShuo Chen printf("now %s\n", muduo::Timestamp::now().toString().c_str()); 162a18e699SShuo Chen} 172a18e699SShuo Chen 182a18e699SShuo Chenvoid print(const char* msg) 192a18e699SShuo Chen{ 202a18e699SShuo Chen printf("msg %s %s\n", muduo::Timestamp::now().toString().c_str(), msg); 212a18e699SShuo Chen if (++cnt == 20) 222a18e699SShuo Chen { 232a18e699SShuo Chen g_loop->quit(); 242a18e699SShuo Chen } 252a18e699SShuo Chen} 262a18e699SShuo Chen 272a18e699SShuo Chenint main() 282a18e699SShuo Chen{ 292a18e699SShuo Chen printTid(); 302a18e699SShuo Chen muduo::EventLoop loop; 312a18e699SShuo Chen g_loop = &loop; 322a18e699SShuo Chen 332a18e699SShuo Chen print("main"); 342a18e699SShuo Chen loop.runAfter(1, boost::bind(print, "once1")); 352a18e699SShuo Chen loop.runAfter(1.5, boost::bind(print, "once1.5")); 362a18e699SShuo Chen loop.runAfter(2.5, boost::bind(print, "once2.5")); 372a18e699SShuo Chen loop.runAfter(3.5, boost::bind(print, "once3.5")); 382a18e699SShuo Chen loop.runEvery(2, boost::bind(print, "every2")); 392a18e699SShuo Chen loop.runEvery(3, boost::bind(print, "every3")); 402a18e699SShuo Chen 412a18e699SShuo Chen loop.loop(); 422a18e699SShuo Chen print("main loop exits"); 432a18e699SShuo Chen sleep(1); 442a18e699SShuo Chen} 45