diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 04de607c7e..523ca06518 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -125,6 +125,7 @@ SrsFastCoroutine::SrsFastCoroutine(string n, ISrsCoroutineHandler* h) trd = NULL; trd_err = srs_success; started = interrupted = disposed = cycle_done = false; + stopping_ = false; // 0 use default, default is 64K. stack_size = 0; @@ -138,6 +139,7 @@ SrsFastCoroutine::SrsFastCoroutine(string n, ISrsCoroutineHandler* h, SrsContext trd = NULL; trd_err = srs_success; started = interrupted = disposed = cycle_done = false; + stopping_ = false; // 0 use default, default is 64K. stack_size = 0; @@ -192,9 +194,14 @@ srs_error_t SrsFastCoroutine::start() void SrsFastCoroutine::stop() { if (disposed) { + if (stopping_) { + srs_error("thread is stopping by %s", stopping_cid_.c_str()); + srs_assert(!stopping_); + } return; } disposed = true; + stopping_ = true; interrupt(); @@ -225,6 +232,9 @@ void SrsFastCoroutine::stop() if (trd_err == srs_success && !cycle_done) { trd_err = srs_error_new(ERROR_THREAD_TERMINATED, "terminated"); } + + // Now, we'are stopped. + stopping_ = false; return; } diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index b881267c34..8357c4b9c5 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -163,6 +163,10 @@ class SrsFastCoroutine bool disposed; // Cycle done, no need to interrupt it. bool cycle_done; +private: + // Sub state in disposed, we need to wait for thread to quit. + bool stopping_; + SrsContextId stopping_cid_; public: SrsFastCoroutine(std::string n, ISrsCoroutineHandler* h); SrsFastCoroutine(std::string n, ISrsCoroutineHandler* h, SrsContextId cid);