1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Add important comment for disposing and thread stop

This commit is contained in:
winlin 2021-03-08 21:05:02 +08:00
parent e4df2eb2ce
commit 55bdc354f5
2 changed files with 8 additions and 2 deletions

View file

@ -47,8 +47,11 @@ public:
virtual ~ISrsDisposingHandler(); virtual ~ISrsDisposingHandler();
public: public:
// When before disposing resource, trigger when manager.remove(c), sync API. // When before disposing resource, trigger when manager.remove(c), sync API.
// @remark Recommend to unref c, after this, no other objects refs to c.
virtual void on_before_dispose(ISrsResource* c) = 0; virtual void on_before_dispose(ISrsResource* c) = 0;
// When disposing resource, async API, c is freed after it. // When disposing resource, async API, c is freed after it.
// @remark Recommend to stop any thread/timer of c, after this, fields of c is able
// to be deleted in any order.
virtual void on_disposing(ISrsResource* c) = 0; virtual void on_disposing(ISrsResource* c) = 0;
}; };

View file

@ -207,13 +207,14 @@ srs_error_t SrsFastCoroutine::start()
void SrsFastCoroutine::stop() void SrsFastCoroutine::stop()
{ {
if (disposed) { if (disposed) {
// TODO: FIXME: If previous stop is wait on st_thread_join, this call should assert fail.
return; return;
} }
disposed = true; disposed = true;
interrupt(); interrupt();
// When not started, the rd is NULL. // When not started, the trd is NULL.
if (trd) { if (trd) {
void* res = NULL; void* res = NULL;
int r0 = st_thread_join((st_thread_t)trd, &res); int r0 = st_thread_join((st_thread_t)trd, &res);
@ -246,6 +247,8 @@ void SrsFastCoroutine::interrupt()
trd_err = srs_error_new(ERROR_THREAD_INTERRUPED, "interrupted"); trd_err = srs_error_new(ERROR_THREAD_INTERRUPED, "interrupted");
} }
// Note that if another thread is stopping thread and waiting in st_thread_join,
// the interrupt will make the st_thread_join fail.
st_thread_interrupt((st_thread_t)trd); st_thread_interrupt((st_thread_t)trd);
} }