|
|
|
@ -66,6 +66,7 @@ namespace internal {
|
|
|
|
|
really_terminated = true;
|
|
|
|
|
_cid = -1;
|
|
|
|
|
_joinable = joinable;
|
|
|
|
|
disposed = false;
|
|
|
|
|
|
|
|
|
|
// in start(), the thread cycle method maybe stop and remove the thread itself,
|
|
|
|
|
// and the thread start() is waiting for the _cid, and segment fault then.
|
|
|
|
@ -115,8 +116,32 @@ namespace internal {
|
|
|
|
|
|
|
|
|
|
void SrsThread::stop()
|
|
|
|
|
{
|
|
|
|
|
if (tid) {
|
|
|
|
|
if (!tid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loop = false;
|
|
|
|
|
|
|
|
|
|
dispose();
|
|
|
|
|
|
|
|
|
|
tid = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SrsThread::can_loop()
|
|
|
|
|
{
|
|
|
|
|
return loop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsThread::stop_loop()
|
|
|
|
|
{
|
|
|
|
|
loop = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsThread::dispose()
|
|
|
|
|
{
|
|
|
|
|
if (disposed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the interrupt will cause the socket to read/write error,
|
|
|
|
|
// which will terminate the cycle thread.
|
|
|
|
@ -145,18 +170,7 @@ namespace internal {
|
|
|
|
|
srs_warn("core: wait thread to actually terminated");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tid = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SrsThread::can_loop()
|
|
|
|
|
{
|
|
|
|
|
return loop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsThread::stop_loop()
|
|
|
|
|
{
|
|
|
|
|
loop = false;
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsThread::thread_cycle()
|
|
|
|
@ -218,8 +232,8 @@ namespace internal {
|
|
|
|
|
handler->on_thread_stop();
|
|
|
|
|
srs_info("thread %s cycle finished", _name);
|
|
|
|
|
|
|
|
|
|
// when thread terminated normally, set the tid to NULL.
|
|
|
|
|
tid = NULL;
|
|
|
|
|
// when thread terminated normally, also disposed.
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* SrsThread::thread_fun(void* arg)
|
|
|
|
|