1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-24 06:54:22 +00:00
srs/trunk/src/app/srs_app_thread.cpp

270 lines
4.9 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2017-03-25 13:29:29 +00:00
* Copyright (c) 2013-2017 OSSRS(winlin)
2017-03-25 09:21:39 +00:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_app_thread.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
2015-05-23 01:20:16 +00:00
ISrsOneCycleThreadHandler::ISrsOneCycleThreadHandler()
{
}
2015-05-23 01:20:16 +00:00
ISrsOneCycleThreadHandler::~ISrsOneCycleThreadHandler()
{
}
2015-05-23 01:49:15 +00:00
void ISrsOneCycleThreadHandler::on_thread_start()
{
}
int ISrsOneCycleThreadHandler::on_before_cycle()
{
return ERROR_SUCCESS;
}
int ISrsOneCycleThreadHandler::on_end_cycle()
{
return ERROR_SUCCESS;
}
2015-05-23 01:20:16 +00:00
void ISrsOneCycleThreadHandler::on_thread_stop()
{
}
2015-05-23 01:20:16 +00:00
SrsOneCycleThread::SrsOneCycleThread(const char* n, ISrsOneCycleThreadHandler* h)
{
2015-05-23 01:20:16 +00:00
handler = h;
pthread = new internal::SrsThread(n, this, 0, false);
}
SrsOneCycleThread::~SrsOneCycleThread()
{
pthread->stop();
srs_freep(pthread);
}
int SrsOneCycleThread::start()
{
return pthread->start();
}
int SrsOneCycleThread::cycle()
{
int ret = handler->cycle();
pthread->stop_loop();
return ret;
}
2015-05-23 01:49:15 +00:00
void SrsOneCycleThread::on_thread_start()
{
handler->on_thread_start();
}
int SrsOneCycleThread::on_before_cycle()
{
return handler->on_before_cycle();
}
int SrsOneCycleThread::on_end_cycle()
{
return handler->on_end_cycle();
}
2015-05-23 01:20:16 +00:00
void SrsOneCycleThread::on_thread_stop()
{
2015-05-23 01:20:16 +00:00
handler->on_thread_stop();
}
2015-02-17 13:10:06 +00:00
2015-05-23 01:20:16 +00:00
ISrsReusableThreadHandler::ISrsReusableThreadHandler()
{
}
2015-02-17 13:10:06 +00:00
2015-05-23 01:20:16 +00:00
ISrsReusableThreadHandler::~ISrsReusableThreadHandler()
{
}
2015-05-23 01:49:15 +00:00
void ISrsReusableThreadHandler::on_thread_start()
{
}
int ISrsReusableThreadHandler::on_before_cycle()
{
return ERROR_SUCCESS;
}
int ISrsReusableThreadHandler::on_end_cycle()
{
return ERROR_SUCCESS;
}
2015-05-23 01:20:16 +00:00
void ISrsReusableThreadHandler::on_thread_stop()
{
}
SrsReusableThread::SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims)
{
2015-05-23 01:20:16 +00:00
handler = h;
pthread = new internal::SrsThread(n, this, cims, true);
}
2015-05-23 01:20:16 +00:00
SrsReusableThread::~SrsReusableThread()
{
2015-05-23 01:20:16 +00:00
pthread->stop();
srs_freep(pthread);
}
2015-02-17 13:10:06 +00:00
2015-05-23 01:20:16 +00:00
int SrsReusableThread::start()
{
return pthread->start();
}
2015-05-23 01:20:16 +00:00
void SrsReusableThread::stop()
{
pthread->stop();
}
2015-09-17 05:36:02 +00:00
bool SrsReusableThread::can_loop()
{
return pthread->can_loop();
}
2015-05-23 01:20:16 +00:00
int SrsReusableThread::cid()
{
2015-05-23 01:20:16 +00:00
return pthread->cid();
}
2015-05-23 01:49:15 +00:00
int SrsReusableThread::cycle()
{
return handler->cycle();
}
void SrsReusableThread::on_thread_start()
{
handler->on_thread_start();
}
int SrsReusableThread::on_before_cycle()
{
return handler->on_before_cycle();
}
int SrsReusableThread::on_end_cycle()
{
return handler->on_end_cycle();
}
void SrsReusableThread::on_thread_stop()
{
handler->on_thread_stop();
}
ISrsReusableThread2Handler::ISrsReusableThread2Handler()
{
}
ISrsReusableThread2Handler::~ISrsReusableThread2Handler()
{
}
void ISrsReusableThread2Handler::on_thread_start()
{
}
int ISrsReusableThread2Handler::on_before_cycle()
{
return ERROR_SUCCESS;
}
int ISrsReusableThread2Handler::on_end_cycle()
{
return ERROR_SUCCESS;
}
void ISrsReusableThread2Handler::on_thread_stop()
{
}
SrsReusableThread2::SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims)
2015-05-23 01:49:15 +00:00
{
handler = h;
pthread = new internal::SrsThread(n, this, cims, true);
2015-05-23 01:49:15 +00:00
}
SrsReusableThread2::~SrsReusableThread2()
{
pthread->stop();
srs_freep(pthread);
}
int SrsReusableThread2::start()
{
return pthread->start();
}
void SrsReusableThread2::stop()
{
pthread->stop();
}
int SrsReusableThread2::cid()
{
return pthread->cid();
}
void SrsReusableThread2::interrupt()
2015-05-23 01:20:16 +00:00
{
pthread->stop_loop();
}
2014-08-02 14:18:39 +00:00
2015-05-23 01:49:15 +00:00
bool SrsReusableThread2::interrupted()
2015-05-23 01:20:16 +00:00
{
return !pthread->can_loop();
}
2015-05-23 01:49:15 +00:00
int SrsReusableThread2::cycle()
2015-05-23 01:20:16 +00:00
{
return handler->cycle();
}
2015-05-23 01:49:15 +00:00
void SrsReusableThread2::on_thread_start()
{
handler->on_thread_start();
}
int SrsReusableThread2::on_before_cycle()
{
return handler->on_before_cycle();
}
int SrsReusableThread2::on_end_cycle()
{
return handler->on_end_cycle();
}
void SrsReusableThread2::on_thread_stop()
2015-05-23 01:20:16 +00:00
{
handler->on_thread_stop();
}
2015-05-23 01:49:15 +00:00