Exemple #1
0
 void SrsThread::dispose()
 {
     if (disposed) {
         return;
     }
     
     // the interrupt will cause the socket to read/write error,
     // which will terminate the cycle thread.
     st_thread_interrupt(tid);
     
     // when joinable, wait util quit.
     if (_joinable) {
         // wait the thread to exit.
         int ret = st_thread_join(tid, NULL);
         if (ret) {
             srs_warn("core: ignore join thread failed.");
         }
     }
     
     // wait the thread actually terminated.
     // sometimes the thread join return -1, for example,
     // when thread use st_recvfrom, the thread join return -1.
     // so here, we use a variable to ensure the thread stopped.
     // @remark even the thread not joinable, we must ensure the thread stopped when stop.
     while (!really_terminated) {
         st_usleep(10 * 1000);
         
         if (really_terminated) {
             break;
         }
         srs_warn("core: wait thread to actually terminated");
     }
     
     disposed = true;
 }
void SrsEncoder::on_unpublish()
{
	if (tid) {
		loop = false;
		st_thread_interrupt(tid);
		st_thread_join(tid, NULL);
		tid = NULL;
	}

	clear_engines();
}
void SrsThread::stop()
{
    if (tid) {
        loop = false;
        
        // the interrupt will cause the socket to read/write error,
        // which will terminate the cycle thread.
        st_thread_interrupt(tid);
        
        // wait the thread to exit.
        st_thread_join(tid, NULL);
        
        tid = NULL;
    }
}
void SrsThread::stop()
{
    if (tid) {
        loop = false;
        
        // the interrupt will cause the socket to read/write error,
        // which will terminate the cycle thread.
        st_thread_interrupt(tid);
        
        // wait the thread to exit.
        int ret = st_thread_join(tid, NULL);
        // TODO: FIXME: the join maybe failed, should use a variable to ensure thread terminated.
        if (ret != 0) {
            srs_warn("join thread failed. code=%d", ret);
        }
        
        tid = NULL;
    }
}