Ai
1 Star 9 Fork 9

John Yet/rtsp_proxy_server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
thread_pool.cpp 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
learnhow 提交于 2020-07-21 11:31 +08:00 . 初始化第一次提交
#include "thread_pool.h"
#include <stdio.h>
#include <QDebug>
using namespace std;
ThreadPool* ThreadPool::Get()
{
static ThreadPool pool;
return &pool;
}
void ThreadPool::Init(int pool_size)
{
for(int i = 0; i < pool_size; i++)
{
StreamThread *st = new StreamThread(i);
st->Start();
thread_list_.push_back(st);
}
}
void ThreadPool::AddTask(StreamTask *task)
{
if(thread_list_.empty())
{
qInfo("线程池还未初始化");
return;
}
list<StreamThread*>::iterator min_it = thread_list_.begin();
for(list<StreamThread*>::iterator it = thread_list_.begin(); it != thread_list_.end(); it++)
{
if(min_it == it)
{
continue;
}
if((*min_it)->TaskSize() > (*it)->TaskSize())
{
min_it = it;
}
}
(*min_it)->AddTask(task);
}
void ThreadPool::RemoveTask(StreamTask *task)
{
for(list<StreamThread*>::iterator it = thread_list_.begin(); it != thread_list_.end(); it++)
{
if((*it)->IsContain(task))
{
(*it)->RemoveTask(task);
}
}
}
void ThreadPool::Destroy()
{
for(list<StreamThread*>::iterator it = thread_list_.begin(); it != thread_list_.end(); it++)
{
StreamThread* st = *it;
st->Stop();
delete st;
}
thread_list_.clear();
}
ThreadPool::ThreadPool()
{
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/learnhow/rtsp_proxy_server.git
git@gitee.com:learnhow/rtsp_proxy_server.git
learnhow
rtsp_proxy_server
rtsp_proxy_server
master

搜索帮助