FT_DECLARE(ftdm_status_t) ftdm_sched_destroy(ftdm_sched_t **insched) { ftdm_sched_t *sched = NULL; ftdm_timer_t *timer; ftdm_timer_t *deltimer; ftdm_assert_return(insched != NULL, FTDM_EINVAL, "sched is null!\n"); ftdm_assert_return(*insched != NULL, FTDM_EINVAL, "sched is null!\n"); sched = *insched; /* since destroying a sched may affect the global list, we gotta check */ ftdm_mutex_lock(sched_globals.mutex); /* if we're head, replace head with our next (whatever our next is, even null will do) */ if (sched == sched_globals.freeruns) { sched_globals.freeruns = sched->next; } /* if we have a previous member (then we were not head) set our previous next to our next */ if (sched->prev) { sched->prev->next = sched->next; } /* if we have a next then set their prev to our prev (if we were head prev will be null and sched->next is already the new head) */ if (sched->next) { sched->next->prev = sched->prev; } ftdm_mutex_unlock(sched_globals.mutex); /* now grab the sched mutex */ ftdm_mutex_lock(sched->mutex); timer = sched->timers; while (timer) { deltimer = timer; timer = timer->next; ftdm_safe_free(deltimer); } ftdm_log(FTDM_LOG_DEBUG, "Destroying schedule %s\n", sched->name); ftdm_mutex_unlock(sched->mutex); ftdm_mutex_destroy(&sched->mutex); ftdm_safe_free(sched); *insched = NULL; return FTDM_SUCCESS; }
static ftdm_status_t ftdm_pritap_stop(ftdm_span_t *span) { pritap_t *pritap = span->signal_data; if (!ftdm_test_flag(pritap, PRITAP_RUNNING)) { return FTDM_FAIL; } ftdm_set_flag(span, FTDM_SPAN_STOP_THREAD); while (ftdm_test_flag(span, FTDM_SPAN_IN_THREAD)) { ftdm_sleep(100); } ftdm_mutex_destroy(&pritap->pcalls_lock); return FTDM_SUCCESS; }
FT_DECLARE(ftdm_status_t) ftdm_sched_create(ftdm_sched_t **sched, const char *name) { ftdm_sched_t *newsched = NULL; ftdm_assert_return(sched != NULL, FTDM_EINVAL, "invalid pointer\n"); ftdm_assert_return(name != NULL, FTDM_EINVAL, "invalid sched name\n"); *sched = NULL; newsched = ftdm_calloc(1, sizeof(*newsched)); if (!newsched) { return FTDM_MEMERR; } if (ftdm_mutex_create(&newsched->mutex) != FTDM_SUCCESS) { goto failed; } ftdm_set_string(newsched->name, name); newsched->currid = 1; *sched = newsched; ftdm_log(FTDM_LOG_DEBUG, "Created schedule %s\n", name); return FTDM_SUCCESS; failed: ftdm_log(FTDM_LOG_CRIT, "Failed to create schedule\n"); if (newsched) { if (newsched->mutex) { ftdm_mutex_destroy(&newsched->mutex); } ftdm_safe_free(newsched); } return FTDM_FAIL; }