From 9944cabd59ceb9039bf465223284b13d48a80239 Mon Sep 17 00:00:00 2001 From: Edmunt Pienkowsky Date: Fri, 21 Jun 2024 07:40:55 +0200 Subject: [PATCH] cli: Improve device completion Use ao2_trylock instead of ao2_lock. --- src/cli.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli.c b/src/cli.c index 1672fcf7..db24d0f0 100644 --- a/src/cli.c +++ b/src/cli.c @@ -58,7 +58,7 @@ static char* complete_device(const char* word, int state) struct ao2_iterator i = ao2_iterator_init(gpublic->pvts, 0); while ((pvt = ao2_iterator_next(&i))) { - if (ao2_lock(pvt)) { + if (ao2_trylock(pvt)) { ao2_ref(pvt, -1); continue; } @@ -94,9 +94,13 @@ static char* cli_show_devices(struct ast_cli_entry* e, int cmd, struct ast_cli_a struct ao2_iterator i = ao2_iterator_init(gpublic->pvts, 0); while ((pvt = ao2_iterator_next(&i))) { - SCOPED_AO2LOCK(pvtl, pvt); + if (ao2_trylock(pvt)) { + ao2_ref(pvt, -1); + continue; + } ast_cli(a->fd, FORMAT2, PVT_ID(pvt), CONF_SHARED(pvt, group), pvt_str_state(pvt), pvt->rssi, pvt->act, pvt->provider_name, pvt->model, pvt->firmware, pvt->imei, pvt->imsi, pvt->subscriber_number); + AO2_UNLOCK_AND_UNREF(pvt); } ao2_iterator_destroy(&i); return CLI_SUCCESS;