mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
async call worker fast execute tasks.
This commit is contained in:
parent
087f7740b7
commit
7b2b11e932
3 changed files with 30 additions and 9 deletions
2
trunk/auto/auto_headers.sh
Executable file → Normal file
2
trunk/auto/auto_headers.sh
Executable file → Normal file
|
@ -257,7 +257,9 @@ echo "\"" >> $SRS_AUTO_HEADERS_H
|
|||
# new empty line to auto headers file.
|
||||
echo "" >> $SRS_AUTO_HEADERS_H
|
||||
|
||||
#####################################################################################
|
||||
# auto header EOF.
|
||||
#####################################################################################
|
||||
echo "#endif" >> $SRS_AUTO_HEADERS_H
|
||||
echo "" >> $SRS_AUTO_HEADERS_H
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ ISrsAsyncCallTask::~ISrsAsyncCallTask()
|
|||
SrsAsyncCallWorker::SrsAsyncCallWorker()
|
||||
{
|
||||
pthread = new SrsReusableThread("async", this, SRS_AUTO_ASYNC_CALLBACL_SLEEP_US);
|
||||
wait = st_cond_new();
|
||||
}
|
||||
|
||||
SrsAsyncCallWorker::~SrsAsyncCallWorker()
|
||||
|
@ -54,6 +55,8 @@ SrsAsyncCallWorker::~SrsAsyncCallWorker()
|
|||
srs_freep(task);
|
||||
}
|
||||
tasks.clear();
|
||||
|
||||
st_cond_destroy(wait);
|
||||
}
|
||||
|
||||
int SrsAsyncCallWorker::execute(ISrsAsyncCallTask* t)
|
||||
|
@ -61,10 +64,16 @@ int SrsAsyncCallWorker::execute(ISrsAsyncCallTask* t)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
tasks.push_back(t);
|
||||
st_cond_signal(wait);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsAsyncCallWorker::count()
|
||||
{
|
||||
return (int)tasks.size();
|
||||
}
|
||||
|
||||
int SrsAsyncCallWorker::start()
|
||||
{
|
||||
return pthread->start();
|
||||
|
@ -72,6 +81,7 @@ int SrsAsyncCallWorker::start()
|
|||
|
||||
void SrsAsyncCallWorker::stop()
|
||||
{
|
||||
st_cond_signal(wait);
|
||||
pthread->stop();
|
||||
}
|
||||
|
||||
|
@ -79,16 +89,22 @@ int SrsAsyncCallWorker::cycle()
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
std::vector<ISrsAsyncCallTask*> copies = tasks;
|
||||
tasks.clear();
|
||||
|
||||
std::vector<ISrsAsyncCallTask*>::iterator it;
|
||||
for (it = copies.begin(); it != copies.end(); ++it) {
|
||||
ISrsAsyncCallTask* task = *it;
|
||||
if ((ret = task->call()) != ERROR_SUCCESS) {
|
||||
srs_warn("ignore async callback %s, ret=%d", task->to_string().c_str(), ret);
|
||||
while (pthread->can_loop()) {
|
||||
if (tasks.empty()) {
|
||||
st_cond_wait(wait);
|
||||
}
|
||||
|
||||
std::vector<ISrsAsyncCallTask*> copies = tasks;
|
||||
tasks.clear();
|
||||
|
||||
std::vector<ISrsAsyncCallTask*>::iterator it;
|
||||
for (it = copies.begin(); it != copies.end(); ++it) {
|
||||
ISrsAsyncCallTask* task = *it;
|
||||
if ((ret = task->call()) != ERROR_SUCCESS) {
|
||||
srs_warn("ignore async callback %s, ret=%d", task->to_string().c_str(), ret);
|
||||
}
|
||||
srs_freep(task);
|
||||
}
|
||||
srs_freep(task);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -70,12 +70,15 @@ class SrsAsyncCallWorker : public ISrsReusableThreadHandler
|
|||
{
|
||||
private:
|
||||
SrsReusableThread* pthread;
|
||||
protected:
|
||||
std::vector<ISrsAsyncCallTask*> tasks;
|
||||
st_cond_t wait;
|
||||
public:
|
||||
SrsAsyncCallWorker();
|
||||
virtual ~SrsAsyncCallWorker();
|
||||
public:
|
||||
virtual int execute(ISrsAsyncCallTask* t);
|
||||
virtual int count();
|
||||
public:
|
||||
virtual int start();
|
||||
virtual void stop();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue