From 79b6c3f9d6db97fa90c3eed73f79cbd9c56c5861 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Fri, 18 Jul 2008 17:33:42 +0000 Subject: [PATCH] Spinlock within the destroy, to allow a scheduled job to continue, if it's waiting on the mutex which the destroy thread has. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@132042 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_iax2.c | 4 ++-- include/asterisk/sched.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 86775358fd..44e11eea37 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -1306,8 +1306,8 @@ retry: } } if (!owner && iaxs[callno]) { - AST_SCHED_DEL(sched, iaxs[callno]->lagid); - AST_SCHED_DEL(sched, iaxs[callno]->pingid); + AST_SCHED_DEL_SPINLOCK(sched, iaxs[callno]->lagid, &iaxsl[callno]); + AST_SCHED_DEL_SPINLOCK(sched, iaxs[callno]->pingid, &iaxsl[callno]); iaxs[callno] = NULL; } diff --git a/include/asterisk/sched.h b/include/asterisk/sched.h index 0a601c7b45..5e51529b96 100644 --- a/include/asterisk/sched.h +++ b/include/asterisk/sched.h @@ -60,6 +60,22 @@ extern "C" { (_sched_res); \ }) +#define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \ + ({ \ + int _count = 0; \ + int _sched_res = -1; \ + while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \ + ast_mutex_unlock(lock); \ + usleep(1); \ + ast_mutex_lock(lock); \ + } \ + if (_count == 10 && option_debug > 2) { \ + ast_log(LOG_DEBUG, "Unable to cancel schedule ID %d.\n", id); \ + } \ + id = -1; \ + (_sched_res); \ + }) + struct sched_context; /*! \brief New schedule context