Skip to content

Commit

Permalink
refine thread stop
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 14, 2016
1 parent fd69391 commit 3df8f11
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions trunk/src/app/srs_app_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ namespace internal
return;
}

loop = false;

dispose();

_cid = -1;
Expand All @@ -152,6 +150,9 @@ namespace internal
return;
}

// notify the cycle to stop loop.
loop = false;

// the interrupt will cause the socket to read/write error,
// which will terminate the cycle thread.
st_thread_interrupt(tid);
Expand Down Expand Up @@ -186,9 +187,11 @@ namespace internal
{
int ret = ERROR_SUCCESS;

// TODO: FIXME: it's better for user to specifies the cid,
// because sometimes we need to merge cid, for example,
// the publish thread should use the same cid of connection.
_srs_context->generate_id();
srs_info("thread %s cycle start", _name);

_cid = _srs_context->get_id();

srs_assert(handler);
Expand Down Expand Up @@ -238,8 +241,9 @@ namespace internal
// readly terminated now.
really_terminated = true;

handler->on_thread_stop();
srs_info("thread %s cycle finished", _name);
// @remark in this callback, user may delete this, so never use this->xxx anymore.
handler->on_thread_stop();
}

void* SrsThread::thread_fun(void* arg)
Expand All @@ -249,7 +253,7 @@ namespace internal

obj->thread_cycle();

// for valgrind to detect.
// delete cid for valgrind to detect memory leak.
SrsThreadContext* ctx = dynamic_cast<SrsThreadContext*>(_srs_context);
if (ctx) {
ctx->clear_cid();
Expand Down

0 comments on commit 3df8f11

Please sign in to comment.