Skip to content

Commit

Permalink
ST: Print log when multiple thread stop one coroutine. (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 15, 2021
1 parent ff33940 commit 93964bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions trunk/src/app/srs_app_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93964bb

Please sign in to comment.