Files
CProxy/lib/event_loop_thread.h
linzhaosheng c682805f71 命名规范
2022-08-21 04:43:21 +08:00

33 lines
701 B
C++

#pragma once
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <thread>
#include "conn.h"
#include "event_loop.h"
class EventLoopThread {
public:
EventLoopThread()
: loop_(new EventLoop()),
thread_(std::bind(&EventLoopThread::ThreadFunc, this)),
mutex_(),
cond_(){};
~EventLoopThread();
void StartLoop();
void ThreadFunc();
void AddChannel(SP_Channel);
void AddConn(SP_Conn);
SP_EventLoop GetLoop() { return loop_; }
private:
SP_EventLoop loop_;
bool started_;
std::thread thread_;
std::mutex mutex_;
std::condition_variable cond_;
};
using SP_EventLoopThread = std::shared_ptr<EventLoopThread>;