Fix indefinite wait when trying to stop pjmedia_clock (#3304)
This commit is contained in:
parent
eca0ae23de
commit
950081c737
|
@ -272,11 +272,15 @@ PJ_DECL(pj_status_t) pjmedia_clock_start(pjmedia_clock *clock);
|
|||
|
||||
|
||||
/**
|
||||
* Stop the clock.
|
||||
* Stop the clock. When the function returns PJ_SUCCESS, it is guaranteed
|
||||
* that the clock thread (if any) has stopped and the callback has completed.
|
||||
* But if the function is called from within the clock's callback itself,
|
||||
* the callback will still be running until completion. In that case,
|
||||
* the function will only stop future callbacks and returns PJ_EBUSY.
|
||||
*
|
||||
* @param clock The media clock.
|
||||
*
|
||||
* @return PJ_SUCCES on success.
|
||||
* @return PJ_SUCCES on success, or PJ_EBUSY.
|
||||
*/
|
||||
PJ_DECL(pj_status_t) pjmedia_clock_stop(pjmedia_clock *clock);
|
||||
|
||||
|
|
|
@ -218,7 +218,15 @@ PJ_DEF(pj_status_t) pjmedia_clock_start(pjmedia_clock *clock)
|
|||
clock->running = PJ_TRUE;
|
||||
clock->quitting = PJ_FALSE;
|
||||
|
||||
if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0 && !clock->thread) {
|
||||
if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0) {
|
||||
if (clock->thread) {
|
||||
/* This is probably the leftover thread that failed to
|
||||
* be cleaned up during the last clock stoppage.
|
||||
*/
|
||||
pj_thread_destroy(clock->thread);
|
||||
clock->thread = NULL;
|
||||
}
|
||||
|
||||
status = pj_thread_create(clock->pool, "clock", &clock_thread, clock,
|
||||
0, 0, &clock->thread);
|
||||
if (status != PJ_SUCCESS) {
|
||||
|
@ -247,7 +255,13 @@ PJ_DEF(pj_status_t) pjmedia_clock_stop(pjmedia_clock *clock)
|
|||
clock->thread = NULL;
|
||||
pj_pool_reset(clock->pool);
|
||||
} else {
|
||||
clock->quitting = PJ_FALSE;
|
||||
/* We are probably called from the clock thread itself.
|
||||
* Do not cancel the thread's quitting though, since it
|
||||
* may cause the clock thread to run indefinitely.
|
||||
*/
|
||||
// clock->quitting = PJ_FALSE;
|
||||
|
||||
return PJ_EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue