From 7ef629e34bc4de769f8d3d082fade225574e24d3 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 27 Jun 2010 18:35:31 -0400 Subject: [PATCH] freetdm: check if the schedule is already running --- libs/freetdm/src/ftdm_sched.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/freetdm/src/ftdm_sched.c b/libs/freetdm/src/ftdm_sched.c index fc9fe60446..5aacc202bf 100644 --- a/libs/freetdm/src/ftdm_sched.c +++ b/libs/freetdm/src/ftdm_sched.c @@ -128,8 +128,16 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_free_run(ftdm_sched_t *sched) ftdm_status_t status = FTDM_FAIL; ftdm_assert_return(sched != NULL, FTDM_EINVAL, "invalid pointer\n"); + ftdm_mutex_lock(sched->mutex); + ftdm_mutex_lock(sched_globals.mutex); + if (sched->freerun) { + ftdm_log(FTDM_LOG_ERROR, "Schedule %s is already running in free run\n", sched->name); + goto done; + } + sched->freerun = 1; + if (sched_globals.running == FTDM_FALSE) { ftdm_log(FTDM_LOG_NOTICE, "Launching main schedule thread\n"); status = ftdm_thread_create_detached(run_main_schedule, NULL); @@ -154,6 +162,8 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_free_run(ftdm_sched_t *sched) done: ftdm_mutex_unlock(sched_globals.mutex); + + ftdm_mutex_unlock(sched->mutex); return status; }