loader: Create ast_module_running_ref.

This function returns NULL if the module in question is not running.  I
did not change ast_module_ref as most callers do not check the result
and they always call ast_module_unref.

Make use of this function when running registered items from:
* app_stack API's
* bridge technologies
* CLI commands
* File formats
* Manager Actions
* RTP engines
* Sorcery Wizards
* Timing Interfaces
* Translators
* AGI Commands
* Fax Technologies

ASTERISK-20346 #close

Change-Id: Ia16fd28e188b2fc0b9d18b8a5d9cacc31df73fcc
This commit is contained in:
Corey Farrell
2017-12-29 19:24:02 -05:00
parent 7f4facc5e4
commit 55f1d69c43
13 changed files with 161 additions and 80 deletions

View File

@@ -124,17 +124,22 @@ struct ast_timer *ast_timer_open(void)
void *data = NULL;
struct timing_holder *h;
struct ast_timer *t = NULL;
int idx = 1;
ast_heap_rdlock(timing_interfaces);
if ((h = ast_heap_peek(timing_interfaces, 1))) {
data = h->iface->timer_open();
ast_module_ref(h->mod);
while ((h = ast_heap_peek(timing_interfaces, idx))) {
if (ast_module_running_ref(h->mod)) {
data = h->iface->timer_open();
break;
}
idx++;
}
if (data) {
if (!(t = ast_calloc(1, sizeof(*t)))) {
h->iface->timer_close(data);
ast_module_unref(h->mod);
} else {
t->data = data;
t->holder = h;