Replace direct access to channel name with accessor functions
[asterisk/asterisk.git] / apps / app_queue.c
index fee840c..ec9ad39 100644 (file)
@@ -1198,12 +1198,6 @@ struct call_queue {
        int autofill;                       /*!< Ignore the head call status and ring an available agent */
        
        struct ao2_container *members;             /*!< Head of the list of members */
-       /*! 
-        * \brief Number of members _logged in_
-        * \note There will be members in the members container that are not logged
-        *       in, so this can not simply be replaced with ao2_container_count(). 
-        */
-       int membercount;
        struct queue_ent *head;             /*!< Head of the list of callers */
        AST_LIST_ENTRY(call_queue) list;    /*!< Next call queue */
        AST_LIST_HEAD_NOLOCK(, penalty_rule) rules; /*!< The list of penalty rules to invoke */
@@ -1678,19 +1672,26 @@ static int compress_char(const char c)
 static int member_hash_fn(const void *obj, const int flags)
 {
        const struct member *mem = obj;
-       const char *chname = strchr(mem->interface, '/');
+       const char *interface = (flags & OBJ_KEY) ? obj : mem->interface;
+       const char *chname = strchr(interface, '/');
        int ret = 0, i;
-       if (!chname)
-               chname = mem->interface;
-       for (i = 0; i < 5 && chname[i]; i++)
+
+       if (!chname) {
+               chname = interface;
+       }
+       for (i = 0; i < 5 && chname[i]; i++) {
                ret += compress_char(chname[i]) << (i * 6);
+       }
        return ret;
 }
 
 static int member_cmp_fn(void *obj1, void *obj2, int flags)
 {
-       struct member *mem1 = obj1, *mem2 = obj2;
-       return strcasecmp(mem1->interface, mem2->interface) ? 0 : CMP_MATCH | CMP_STOP;
+       struct member *mem1 = obj1;
+       struct member *mem2 = obj2;
+       const char *interface = (flags & OBJ_KEY) ? obj2 : mem2->interface;
+
+       return strcasecmp(mem1->interface, interface) ? 0 : CMP_MATCH | CMP_STOP;
 }
 
 /*!
@@ -2196,14 +2197,13 @@ static void rt_handle_member_record(struct call_queue *q, char *interface, struc
                        m->ignorebusy = ignorebusy;
                        ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid));
                        if (!log_membername_as_agent) {
-                               ast_queue_log(q->name, "REALTIME", m->interface, "ADDMEMBER", "%s", "");
+                               ast_queue_log(q->name, "REALTIME", m->interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
                        } else {
-                               ast_queue_log(q->name, "REALTIME", m->membername, "ADDMEMBER", "%s", "");
+                               ast_queue_log(q->name, "REALTIME", m->membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
                        }
                        ao2_link(q->members, m);
                        ao2_ref(m, -1);
                        m = NULL;
-                       q->membercount++;
                }
        }
 }
@@ -2218,7 +2218,6 @@ static void free_members(struct call_queue *q, int all)
        while ((cur = ao2_iterator_next(&mem_iter))) {
                if (all || !cur->dynamic) {
                        ao2_unlink(q->members, cur);
-                       q->membercount--;
                }
                ao2_ref(cur, -1);
        }
@@ -2322,7 +2321,6 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
                ao2_lock(q);
                clear_queue(q);
                q->realtime = 1;
-               q->membercount = 0;
                /*Before we initialize the queue, we need to set the strategy, so that linear strategy
                 * will allocate the members properly
                 */
@@ -2363,11 +2361,9 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
                queue_set_param(q, tmp_name, v->value, -1, 0);
        }
 
-       /* Temporarily set realtime members dead so we can detect deleted ones.
-        * Also set the membercount correctly for realtime*/
+       /* Temporarily set realtime members dead so we can detect deleted ones. */
        mem_iter = ao2_iterator_init(q->members, 0);
        while ((m = ao2_iterator_next(&mem_iter))) {
-               q->membercount++;
                if (m->realtime) {
                        m->dead = 1;
                }
@@ -2389,7 +2385,6 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
                                ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
                        }
                        ao2_unlink(q->members, m);
-                       q->membercount--;
                }
                ao2_ref(m, -1);
        }
@@ -2400,8 +2395,18 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
        return q;
 }
 
-/*! \note Returns a reference to the loaded realtime queue. */
-static struct call_queue *load_realtime_queue(const char *queuename)
+/*!
+ * note  */
+
+/*!
+ * \internal
+ * \brief Returns reference to the named queue. If the queue is realtime, it will load the queue as well.
+ * \param queuename - name of the desired queue
+ *
+ * \retval the queue
+ * \retval NULL if it doesn't exist
+ */
+static struct call_queue *find_load_queue_rt_friendly(const char *queuename)
 {
        struct ast_variable *queue_vars;
        struct ast_config *member_config = NULL;
@@ -2509,7 +2514,6 @@ static void update_realtime_members(struct call_queue *q)
                                ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
                        }
                        ao2_unlink(q->members, m);
-                       q->membercount--;
                }
                ao2_ref(m, -1);
        }
@@ -2526,7 +2530,7 @@ static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *
        int pos = 0;
        int inserted = 0;
 
-       if (!(q = load_realtime_queue(queuename))) {
+       if (!(q = find_load_queue_rt_friendly(queuename))) {
                return res;
        }
        ao2_lock(q);
@@ -2591,13 +2595,13 @@ static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *
                        "Position: %d\r\n"
                        "Count: %d\r\n"
                        "Uniqueid: %s\r\n",
-                       qe->chan->name,
+                       ast_channel_name(qe->chan),
                        S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, "unknown"),/* XXX somewhere else it is <unknown> */
                        S_COR(qe->chan->caller.id.name.valid, qe->chan->caller.id.name.str, "unknown"),
                        S_COR(qe->chan->connected.id.number.valid, qe->chan->connected.id.number.str, "unknown"),/* XXX somewhere else it is <unknown> */
                        S_COR(qe->chan->connected.id.name.valid, qe->chan->connected.id.name.str, "unknown"),
                        q->name, qe->pos, q->count, qe->chan->uniqueid );
-               ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
+               ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, ast_channel_name(qe->chan), qe->pos );
        }
        ao2_unlock(q);
        queue_t_unref(q, "Done with realtime queue");
@@ -2786,7 +2790,7 @@ static int say_position(struct queue_ent *qe, int ringing)
 posout:
        if (qe->parent->announceposition) {
                ast_verb(3, "Told %s in %s their queue position (which was %d)\n",
-                       qe->chan->name, qe->parent->name, qe->pos);
+                       ast_channel_name(qe->chan), qe->parent->name, qe->pos);
        }
        if (say_thanks) {
                res = play_file(qe->chan, qe->parent->sound_thanks);
@@ -2852,8 +2856,8 @@ static void leave_queue(struct queue_ent *qe)
                        /* Take us out of the queue */
                        ast_manager_event(qe->chan, EVENT_FLAG_CALL, "Leave",
                                "Channel: %s\r\nQueue: %s\r\nCount: %d\r\nPosition: %d\r\nUniqueid: %s\r\n",
-                               qe->chan->name, q->name,  q->count, qe->pos, qe->chan->uniqueid);
-                       ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, qe->chan->name );
+                               ast_channel_name(qe->chan), q->name,  q->count, qe->pos, qe->chan->uniqueid);
+                       ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, ast_channel_name(qe->chan));
                        /* Take us out of the queue */
                        if (prev)
                                prev->next = current->next;
@@ -3165,10 +3169,7 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
                return 0;
        }
 
-       ast_channel_lock(tmp->chan);
-       while (ast_channel_trylock(qe->chan)) {
-               CHANNEL_DEADLOCK_AVOIDANCE(tmp->chan);
-       }
+       ast_channel_lock_both(tmp->chan, qe->chan);
 
        if (qe->cancel_answered_elsewhere) {
                ast_set_flag(tmp->chan, AST_FLAG_ANSWERED_ELSEWHERE);
@@ -3218,7 +3219,7 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
        if (ast_cdr_isset_unanswered()) {
                /* they want to see the unanswered dial attempts! */
                /* set up the CDR fields on all the CDRs to give sensical information */
-               ast_cdr_setdestchan(tmp->chan->cdr, tmp->chan->name);
+               ast_cdr_setdestchan(tmp->chan->cdr, ast_channel_name(tmp->chan));
                strcpy(tmp->chan->cdr->clid, qe->chan->cdr->clid);
                strcpy(tmp->chan->cdr->channel, qe->chan->cdr->channel);
                strcpy(tmp->chan->cdr->src, qe->chan->cdr->src);
@@ -3231,13 +3232,14 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
                strcpy(tmp->chan->cdr->userfield, qe->chan->cdr->userfield);
        }
 
+       ast_channel_unlock(tmp->chan);
+       ast_channel_unlock(qe->chan);
+
        /* Place the call, but don't wait on the answer */
        if ((res = ast_call(tmp->chan, location, 0))) {
                /* Again, keep going even if there's an error */
                ast_debug(1, "ast call on peer returned %d\n", res);
                ast_verb(3, "Couldn't call %s\n", tmp->interface);
-               ast_channel_unlock(tmp->chan);
-               ast_channel_unlock(qe->chan);
                do_hang(tmp);
                (*busies)++;
                update_status(qe->parent, tmp->member, get_queue_member_status(tmp->member));
@@ -3245,6 +3247,8 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
        } else if (qe->parent->eventwhencalled) {
                char vars[2048];
 
+               ast_channel_lock_both(tmp->chan, qe->chan);
+
                manager_event(EVENT_FLAG_AGENT, "AgentCalled",
                        "Queue: %s\r\n"
                        "AgentCalled: %s\r\n"
@@ -3260,17 +3264,19 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
                        "Priority: %d\r\n"
                        "Uniqueid: %s\r\n"
                        "%s",
-                       qe->parent->name, tmp->interface, tmp->member->membername, qe->chan->name, tmp->chan->name,
-                       S_COR(tmp->chan->caller.id.number.valid, tmp->chan->caller.id.number.str, "unknown"),
-                       S_COR(tmp->chan->caller.id.name.valid, tmp->chan->caller.id.name.str, "unknown"),
-                       S_COR(tmp->chan->connected.id.number.valid, tmp->chan->connected.id.number.str, "unknown"),
-                       S_COR(tmp->chan->connected.id.name.valid, tmp->chan->connected.id.name.str, "unknown"),
+                       qe->parent->name, tmp->interface, tmp->member->membername, ast_channel_name(qe->chan), ast_channel_name(tmp->chan),
+                       S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, "unknown"),
+                       S_COR(qe->chan->caller.id.name.valid, qe->chan->caller.id.name.str, "unknown"),
+                       S_COR(qe->chan->connected.id.number.valid, qe->chan->connected.id.number.str, "unknown"),
+                       S_COR(qe->chan->connected.id.name.valid, qe->chan->connected.id.name.str, "unknown"),
                        qe->chan->context, qe->chan->exten, qe->chan->priority, qe->chan->uniqueid,
                        qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : "");
+
+               ast_channel_unlock(tmp->chan);
+               ast_channel_unlock(qe->chan);
+
                ast_verb(3, "Called %s\n", tmp->interface);
        }
-       ast_channel_unlock(tmp->chan);
-       ast_channel_unlock(qe->chan);
 
        update_status(qe->parent, tmp->member, get_queue_member_status(tmp->member));
        return 1;
@@ -3483,7 +3489,7 @@ static void rna(int rnatime, struct queue_ent *qe, char *interface, char *member
                                                "%s",
                                                qe->parent->name,
                                                qe->chan->uniqueid,
-                                               qe->chan->name,
+                                               ast_channel_name(qe->chan),
                                                interface,
                                                membername,
                                                rnatime,
@@ -3498,8 +3504,10 @@ static void rna(int rnatime, struct queue_ent *qe, char *interface, char *member
                                time_t idletime = time(&idletime)-mem->lastcall;
                                if ((mem->lastcall != 0) && (qe->parent->autopausedelay > idletime)) {
                                        ao2_unlock(qe->parent);
+                                       ao2_ref(mem, -1);
                                        return;
                                }
+                               ao2_ref(mem, -1);
                        }
                        ao2_unlock(qe->parent);
                }
@@ -3566,7 +3574,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
        ast_party_connected_line_init(&connected_caller);
 
        ast_channel_lock(qe->chan);
-       inchan_name = ast_strdupa(qe->chan->name);
+       inchan_name = ast_strdupa(ast_channel_name(qe->chan));
        ast_channel_unlock(qe->chan);
 
        starttime = (long) time(NULL);
@@ -3630,7 +3638,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
                        char ochan_name[AST_CHANNEL_NAME];
                        if (o->chan) {
                                ast_channel_lock(o->chan);
-                               ast_copy_string(ochan_name, o->chan->name, sizeof(ochan_name));
+                               ast_copy_string(ochan_name, ast_channel_name(o->chan), sizeof(ochan_name));
                                ast_channel_unlock(o->chan);
                        }
                        if (o->stillgoing && (o->chan) &&  (o->chan->_state == AST_STATE_UP)) {
@@ -3702,10 +3710,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
                                        } else {
                                                struct ast_party_redirecting redirecting;
 
-                                               ast_channel_lock(o->chan);
-                                               while (ast_channel_trylock(in)) {
-                                                       CHANNEL_DEADLOCK_AVOIDANCE(o->chan);
-                                               }
+                                               ast_channel_lock_both(o->chan, in);
                                                ast_channel_inherit_variables(in, o->chan);
                                                ast_channel_datastore_inherit(in, o->chan);
 
@@ -3985,10 +3990,10 @@ static int is_our_turn(struct queue_ent *qe)
         * from the front of the queue are valid when autofill is disabled)
         */
        if (ch && idx < avl && (qe->parent->autofill || qe->pos == 1)) {
-               ast_debug(1, "It's our turn (%s).\n", qe->chan->name);
+               ast_debug(1, "It's our turn (%s).\n", ast_channel_name(qe->chan));
                res = 1;
        } else {
-               ast_debug(1, "It's not our turn (%s).\n", qe->chan->name);
+               ast_debug(1, "It's not our turn (%s).\n", ast_channel_name(qe->chan));
                res = 0;
        }
 
@@ -4019,7 +4024,7 @@ static void update_qe_rule(struct queue_ent *qe)
        pbx_builtin_setvar_helper(qe->chan, "QUEUE_MIN_PENALTY", min_penalty_str);
        qe->max_penalty = max_penalty;
        qe->min_penalty = min_penalty;
-       ast_debug(3, "Setting max penalty to %d and min penalty to %d for caller %s since %d seconds have elapsed\n", qe->max_penalty, qe->min_penalty, qe->chan->name, qe->pr->time);
+       ast_debug(3, "Setting max penalty to %d and min penalty to %d for caller %s since %d seconds have elapsed\n", qe->max_penalty, qe->min_penalty, ast_channel_name(qe->chan), qe->pr->time);
        qe->pr = AST_LIST_NEXT(qe->pr, list);
 }
 
@@ -4160,7 +4165,8 @@ static int update_queue(struct call_queue *q, struct member *member, int callcom
 static int calc_metric(struct call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct callattempt *tmp)
 {
        /* disregarding penalty on too few members? */
-       unsigned char usepenalty = (q->membercount <= q->penaltymemberslimit) ? 0 : 1;
+       int membercount = ao2_container_count(q->members);
+       unsigned char usepenalty = (membercount <= q->penaltymemberslimit) ? 0 : 1;
 
        if (usepenalty) {
                if ((qe->max_penalty && (mem->penalty > qe->max_penalty)) ||
@@ -4169,7 +4175,7 @@ static int calc_metric(struct call_queue *q, struct member *mem, int pos, struct
                }
        } else {
                ast_debug(1, "Disregarding penalty, %d members and %d in penaltymemberslimit.\n",
-                         q->membercount, q->penaltymemberslimit);
+                         membercount, q->penaltymemberslimit);
        }
 
        switch (q->strategy) {
@@ -4263,7 +4269,7 @@ static void send_agent_complete(const struct queue_ent *qe, const char *queuenam
                "TalkTime: %ld\r\n"
                "Reason: %s\r\n"
                "%s",
-               queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
+               queuename, qe->chan->uniqueid, ast_channel_name(peer), member->interface, member->membername,
                (long)(callstart - qe->start), (long)(time(NULL) - callstart), reason,
                qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, vars_len) : "");
 }
@@ -4512,7 +4518,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                        if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_LINEAR || qe->parent->strategy == QUEUE_STRATEGY_RRORDERED)
                                (*tries)++;
                        else
-                               *tries = qe->parent->membercount;
+                               *tries = ao2_container_count(qe->parent->members);
                        *noption = 1;
                        break;
                case 'i':
@@ -4541,7 +4547,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
 
        ao2_lock(qe->parent);
        ast_debug(1, "%s is trying to call a queue member.\n",
-                                                       qe->chan->name);
+                                                       ast_channel_name(qe->chan));
        ast_copy_string(queuename, qe->parent->name, sizeof(queuename));
        if (!ast_strlen_zero(qe->announce))
                announce = qe->announce;
@@ -4702,7 +4708,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                        res = digit;
                }
                if (res == -1)
-                       ast_debug(1, "%s: Nobody answered.\n", qe->chan->name);
+                       ast_debug(1, "%s: Nobody answered.\n", ast_channel_name(qe->chan));
                if (ast_cdr_isset_unanswered()) {
                        /* channel contains the name of one of the outgoing channels
                           in its CDR; zero out this CDR to avoid a dual-posting */
@@ -4769,7 +4775,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                        res2 |= ast_autoservice_stop(qe->chan);
                        if (ast_check_hangup(peer)) {
                                /* Agent must have hung up */
-                               ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", peer->name);
+                               ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", ast_channel_name(peer));
                                ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "AGENTDUMP", "%s", "");
                                if (qe->parent->eventwhencalled)
                                        manager_event(EVENT_FLAG_AGENT, "AgentDump",
@@ -4779,14 +4785,14 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                                        "Member: %s\r\n"
                                                        "MemberName: %s\r\n"
                                                        "%s",
-                                                       queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
+                                                       queuename, qe->chan->uniqueid, ast_channel_name(peer), member->interface, member->membername,
                                                        qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : "");
                                ast_hangup(peer);
                                ao2_ref(member, -1);
                                goto out;
                        } else if (res2) {
                                /* Caller must have hung up just before being connected*/
-                               ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", peer->name);
+                               ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", ast_channel_name(peer));
                                ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long) time(NULL) - qe->start);
                                record_abandoned(qe);
                                ast_hangup(peer);
@@ -4801,13 +4807,13 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                        ast_moh_stop(qe->chan);
                /* If appropriate, log that we have a destination channel */
                if (qe->chan->cdr) {
-                       ast_cdr_setdestchan(qe->chan->cdr, peer->name);
+                       ast_cdr_setdestchan(qe->chan->cdr, ast_channel_name(peer));
                }
                /* Make sure channels are compatible */
                res = ast_channel_make_compatible(qe->chan, peer);
                if (res < 0) {
                        ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "SYSCOMPAT", "%s", "");
-                       ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", qe->chan->name, peer->name);
+                       ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(qe->chan), ast_channel_name(peer));
                        record_abandoned(qe);
                        ast_cdr_failed(qe->chan->cdr);
                        ast_hangup(peer);
@@ -5110,9 +5116,9 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                        if ((strcasecmp(cdr->uniqueid, qe->chan->uniqueid)) &&
                            (strcasecmp(cdr->linkedid, qe->chan->uniqueid)) &&
                            (newcdr = ast_cdr_dup(cdr))) {
+                               ast_channel_lock(qe->chan);
                                ast_cdr_init(newcdr, qe->chan);
                                ast_cdr_reset(newcdr, 0);
-                               ast_channel_lock(qe->chan);
                                cdr = ast_cdr_append(cdr, newcdr);
                                cdr = cdr->next;
                                ast_channel_unlock(qe->chan);
@@ -5134,7 +5140,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                        "BridgedChannel: %s\r\n"
                                        "Ringtime: %ld\r\n"
                                        "%s",
-                                       queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
+                                       queuename, qe->chan->uniqueid, ast_channel_name(peer), member->interface, member->membername,
                                        (long) time(NULL) - qe->start, peer->uniqueid, (long)(orig - to > 0 ? (orig - to) / 1000 : 0),
                                        qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : "");
                ast_copy_string(oldcontext, qe->chan->context, sizeof(oldcontext));
@@ -5312,7 +5318,6 @@ static int remove_from_queue(const char *queuename, const char *interface)
                                queue_t_unref(q, "Interface wasn't dynamic, expiring temporary reference");
                                return RES_NOT_DYNAMIC;
                        }
-                       q->membercount--;
                        manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved",
                                "Queue: %s\r\n"
                                "Location: %s\r\n"
@@ -5350,7 +5355,7 @@ static int add_to_queue(const char *queuename, const char *interface, const char
 
        /*! \note Ensure the appropriate realtime queue is loaded.  Note that this
         * short-circuits if the queue is already in memory. */
-       if (!(q = load_realtime_queue(queuename))) {
+       if (!(q = find_load_queue_rt_friendly(queuename))) {
                return res;
        }
 
@@ -5359,7 +5364,6 @@ static int add_to_queue(const char *queuename, const char *interface, const char
                if ((new_member = create_queue_member(interface, membername, penalty, paused, state_interface))) {
                        new_member->dynamic = 1;
                        ao2_link(q->members, new_member);
-                       q->membercount++;
                        manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
                                "Queue: %s\r\n"
                                "Location: %s\r\n"
@@ -5473,45 +5477,95 @@ static int set_member_paused(const char *queuename, const char *interface, const
        return found ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
-/* \brief Sets members penalty, if queuename=NULL we set member penalty in all the queues. */
+/*!
+ * \internal
+ * \brief helper function for set_member_penalty - given a queue, sets all member penalties with the interface
+ * \param[in] q queue which is having its member's penalty changed - must be unlocked prior to calling
+ * \param[in] interface String of interface used to search for queue members being changed
+ * \param[in] penalty Value penalty is being changed to for the member.
+ * \retval 0 if the there is no member with interface belonging to q and no change is made
+ * \retval 1 if the there is a member with interface belonging to q and changes are made
+ */
+static int set_member_penalty_help_members(struct call_queue *q, const char *interface, int penalty)
+{
+       struct member *mem;
+       int foundinterface = 0;
+       char rtpenalty[80];
+
+       ao2_lock(q);
+       if ((mem = interface_exists(q, interface))) {
+               foundinterface++;
+               if (!mem->realtime) {
+                       mem->penalty = penalty;
+               } else {
+                       sprintf(rtpenalty, "%i", penalty);
+                       update_realtime_member_field(mem, q->name, "penalty", rtpenalty);
+               }
+               ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty);
+               manager_event(EVENT_FLAG_AGENT, "QueueMemberPenalty",
+                       "Queue: %s\r\n"
+                       "Location: %s\r\n"
+                       "Penalty: %d\r\n",
+                       q->name, mem->interface, penalty);
+               ao2_ref(mem, -1);
+       }
+       ao2_unlock(q);
+
+       return foundinterface;
+}
+
+/*!
+ * \internal
+ * \brief Sets members penalty, if queuename=NULL we set member penalty in all the queues.
+ * \param[in] queuename If specified, only act on a member if it belongs to this queue
+ * \param[in] interface Interface of queue member(s) having priority set.
+ * \param[in] penalty Value penalty is being changed to for each member
+ */
 static int set_member_penalty(const char *queuename, const char *interface, int penalty)
 {
        int foundinterface = 0, foundqueue = 0;
        struct call_queue *q;
-       struct member *mem;
-       char rtpenalty[80];
+       struct ast_config *queue_config = NULL;
+       struct ao2_iterator queue_iter;
 
        if (penalty < 0 && !negative_penalty_invalid) {
                ast_log(LOG_ERROR, "Invalid penalty (%d)\n", penalty);
                return RESULT_FAILURE;
        }
 
-       if ((q = load_realtime_queue(queuename))) {
-               foundqueue++;
-               ao2_lock(q);
-               if ((mem = interface_exists(q, interface))) {
-                       foundinterface++;
-                       if (!mem->realtime) {
-                               mem->penalty = penalty;
-                       } else {
-                               sprintf(rtpenalty,"%i", penalty);
-                               update_realtime_member_field(mem, q->name, "penalty", rtpenalty);
+       if (ast_strlen_zero(queuename)) { /* This means we need to iterate through all the queues. */
+               if (ast_check_realtime("queues")) {
+                       char *queuename;
+                       queue_config = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
+                       if (queue_config) {
+                               for (queuename = ast_category_browse(queue_config, NULL); !ast_strlen_zero(queuename); queuename = ast_category_browse(queue_config, queuename)) {
+                                       if ((q = find_load_queue_rt_friendly(queuename))) {
+                                               foundqueue++;
+                                               foundinterface += set_member_penalty_help_members(q, interface, penalty);
+                                       }
+                               }
                        }
-                       ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty);
-                       manager_event(EVENT_FLAG_AGENT, "QueueMemberPenalty",
-                               "Queue: %s\r\n"
-                               "Location: %s\r\n"
-                               "Penalty: %d\r\n",
-                               q->name, mem->interface, penalty);
-                       ao2_ref(mem, -1);
                }
-               ao2_unlock(q);
+
+               /* After hitting realtime queues, go back and get the regular ones. */
+               queue_iter = ao2_iterator_init(queues, 0);
+
+               while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
+                       foundqueue++;
+                       foundinterface += set_member_penalty_help_members(q, interface, penalty);
+               }
+
+       } else { /* We actually have a queuename, so we can just act on the single queue. */
+               if ((q = find_load_queue_rt_friendly(queuename))) {
+                       foundqueue++;
+                       foundinterface += set_member_penalty_help_members(q, interface, penalty);
+               }
        }
 
        if (foundinterface) {
                return RESULT_SUCCESS;
        } else if (!foundqueue) {
-               ast_log (LOG_ERROR, "Invalid queuename\n"); 
+               ast_log (LOG_ERROR, "Invalid queuename\n");
        } else {
                ast_log (LOG_ERROR, "Invalid interface\n");
        }
@@ -5586,7 +5640,7 @@ static void reload_queue_members(void)
                }
 
                if (!cur_queue) {
-                       cur_queue = load_realtime_queue(queue_name);
+                       cur_queue = find_load_queue_rt_friendly(queue_name);
                }
 
                if (!cur_queue) {
@@ -5745,7 +5799,7 @@ static int rqm_exec(struct ast_channel *chan, const char *data)
        AST_STANDARD_APP_ARGS(args, parse);
 
        if (ast_strlen_zero(args.interface)) {
-               args.interface = ast_strdupa(chan->name);
+               args.interface = ast_strdupa(ast_channel_name(chan));
                temppos = strrchr(args.interface, '-');
                if (temppos)
                        *temppos = '\0';
@@ -5759,7 +5813,7 @@ static int rqm_exec(struct ast_channel *chan, const char *data)
 
        switch (remove_from_queue(args.queuename, args.interface)) {
        case RES_OKAY:
-               if (!mem || ast_strlen_zero(mem->membername) || !log_membername_as_agent) {
+               if (!mem || ast_strlen_zero(mem->membername)) {
                        ast_queue_log(args.queuename, chan->uniqueid, args.interface, "REMOVEMEMBER", "%s", "");
                } else {
                        ast_queue_log(args.queuename, chan->uniqueid, mem->membername, "REMOVEMEMBER", "%s", "");
@@ -5785,6 +5839,10 @@ static int rqm_exec(struct ast_channel *chan, const char *data)
                break;
        }
 
+       if (mem) {
+               ao2_ref(mem, -1);
+       }
+
        return res;
 }
 
@@ -5813,7 +5871,7 @@ static int aqm_exec(struct ast_channel *chan, const char *data)
        AST_STANDARD_APP_ARGS(args, parse);
 
        if (ast_strlen_zero(args.interface)) {
-               args.interface = ast_strdupa(chan->name);
+               args.interface = ast_strdupa(ast_channel_name(chan));
                temppos = strrchr(args.interface, '-');
                if (temppos)
                        *temppos = '\0';
@@ -5984,10 +6042,10 @@ static int queue_exec(struct ast_channel *chan, const char *data)
        user_priority = pbx_builtin_getvar_helper(chan, "QUEUE_PRIO");
        if (user_priority) {
                if (sscanf(user_priority, "%30d", &prio) == 1) {
-                       ast_debug(1, "%s: Got priority %d from ${QUEUE_PRIO}.\n", chan->name, prio);
+                       ast_debug(1, "%s: Got priority %d from ${QUEUE_PRIO}.\n", ast_channel_name(chan), prio);
                } else {
                        ast_log(LOG_WARNING, "${QUEUE_PRIO}: Invalid value (%s), channel %s.\n",
-                               user_priority, chan->name);
+                               user_priority, ast_channel_name(chan));
                        prio = 0;
                }
        } else {
@@ -5999,10 +6057,10 @@ static int queue_exec(struct ast_channel *chan, const char *data)
 
        if ((max_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MAX_PENALTY"))) {
                if (sscanf(max_penalty_str, "%30d", &max_penalty) == 1) {
-                       ast_debug(1, "%s: Got max penalty %d from ${QUEUE_MAX_PENALTY}.\n", chan->name, max_penalty);
+                       ast_debug(1, "%s: Got max penalty %d from ${QUEUE_MAX_PENALTY}.\n", ast_channel_name(chan), max_penalty);
                } else {
                        ast_log(LOG_WARNING, "${QUEUE_MAX_PENALTY}: Invalid value (%s), channel %s.\n",
-                               max_penalty_str, chan->name);
+                               max_penalty_str, ast_channel_name(chan));
                        max_penalty = 0;
                }
        } else {
@@ -6011,10 +6069,10 @@ static int queue_exec(struct ast_channel *chan, const char *data)
 
        if ((min_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MIN_PENALTY"))) {
                if (sscanf(min_penalty_str, "%30d", &min_penalty) == 1) {
-                       ast_debug(1, "%s: Got min penalty %d from ${QUEUE_MIN_PENALTY}.\n", chan->name, min_penalty);
+                       ast_debug(1, "%s: Got min penalty %d from ${QUEUE_MIN_PENALTY}.\n", ast_channel_name(chan), min_penalty);
                } else {
                        ast_log(LOG_WARNING, "${QUEUE_MIN_PENALTY}: Invalid value (%s), channel %s.\n",
-                               min_penalty_str, chan->name);
+                               min_penalty_str, ast_channel_name(chan));
                        min_penalty = 0;
                }
        } else {
@@ -6139,7 +6197,7 @@ check_turns:
                }
 
                /* exit after 'timeout' cycle if 'n' option enabled */
-               if (noption && tries >= qe.parent->membercount) {
+               if (noption && tries >= ao2_container_count(qe.parent->members)) {
                        ast_verb(3, "Exiting on time-out cycle\n");
                        ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
                        record_abandoned(&qe);
@@ -6170,7 +6228,7 @@ check_turns:
                 * of the queue, go and check for our turn again.
                 */
                if (!is_our_turn(&qe)) {
-                       ast_debug(1, "Darn priorities, going back in queue (%s)!\n", qe.chan->name);
+                       ast_debug(1, "Darn priorities, going back in queue (%s)!\n", ast_channel_name(qe.chan));
                        goto check_turns;
                }
        }
@@ -6283,7 +6341,7 @@ static int queue_function_exists(struct ast_channel *chan, const char *cmd, char
                ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
                return -1;
        }
-       q = load_realtime_queue(data);
+       q = find_load_queue_rt_friendly(data);
        snprintf(buf, len, "%d", q != NULL? 1 : 0);
        if (q) {
                queue_t_unref(q, "Done with temporary reference in QUEUE_EXISTS()");
@@ -6314,13 +6372,18 @@ static int queue_function_mem_read(struct ast_channel *chan, const char *cmd, ch
        buf[0] = '\0';
 
        if (ast_strlen_zero(data)) {
-               ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
+               ast_log(LOG_ERROR, "Missing required argument. %s(<queuename>,<option>[<interface>])\n", cmd);
                return -1;
        }
 
        AST_STANDARD_APP_ARGS(args, data);
 
-       if ((q = load_realtime_queue(args.queuename))) {
+       if (args.argc < 2) {
+               ast_log(LOG_ERROR, "Missing required argument. %s(<queuename>,<option>[<interface>])\n", cmd);
+               return -1;
+       }
+
+       if ((q = find_load_queue_rt_friendly(args.queuename))) {
                ao2_lock(q);
                if (!strcasecmp(args.option, "logged")) {
                        mem_iter = ao2_iterator_init(q->members, 0);
@@ -6356,16 +6419,22 @@ static int queue_function_mem_read(struct ast_channel *chan, const char *cmd, ch
                        }
                        ao2_iterator_destroy(&mem_iter);
                } else if (!strcasecmp(args.option, "count") || ast_strlen_zero(args.option)) {
-                       count = q->membercount;
+                       count = ao2_container_count(q->members);
                } else if (!strcasecmp(args.option, "penalty") && !ast_strlen_zero(args.interface) &&
                           ((m = interface_exists(q, args.interface)))) {
                        count = m->penalty;
+                       ao2_ref(m, -1);
                } else if (!strcasecmp(args.option, "paused") && !ast_strlen_zero(args.interface) &&
                           ((m = interface_exists(q, args.interface)))) {
                        count = m->paused;
+                       ao2_ref(m, -1);
                } else if (!strcasecmp(args.option, "ignorebusy") && !ast_strlen_zero(args.interface) &&
                           ((m = interface_exists(q, args.interface)))) {
                        count = m->ignorebusy;
+                       ao2_ref(m, -1);
+               } else {
+                       ast_log(LOG_ERROR, "Unknown option %s provided to %s, valid values are: "
+                               "logged, free, ready, count, penalty, paused, ignorebusy\n", args.option, cmd);
                }
                ao2_unlock(q);
                queue_t_unref(q, "Done with temporary reference in QUEUE_MEMBER()");
@@ -6417,7 +6486,7 @@ static int queue_function_mem_write(struct ast_channel *chan, const char *cmd, c
                        ast_log(LOG_ERROR, "Invalid interface, queue or penalty\n");
                        return -1;
                }
-       } else if ((q = load_realtime_queue(args.queuename))) {
+       } else if ((q = find_load_queue_rt_friendly(args.queuename))) {
                ao2_lock(q);
                if ((m = interface_exists(q, args.interface))) {
                        sprintf(rtvalue, "%s",(memvalue <= 0) ? "0" : "1");
@@ -6435,13 +6504,20 @@ static int queue_function_mem_write(struct ast_channel *chan, const char *cmd, c
                                }
                        } else {
                                ast_log(LOG_ERROR, "Invalid option, only penalty , paused or ignorebusy are valid\n");
+                               ao2_ref(m, -1);
+                               ao2_unlock(q);
+                               ao2_ref(q, -1);
                                return -1;
                        }
+                       ao2_ref(m, -1);
                } else {
-                       ast_log(LOG_ERROR, "Invalid interface or queue\n");
+                       ao2_unlock(q);
+                       ao2_ref(q, -1);
+                       ast_log(LOG_ERROR, "Invalid interface for queue\n");
                        return -1;
                }
                ao2_unlock(q);
+               ao2_ref(q, -1);
         } else {
                ast_log(LOG_ERROR, "Invalid queue\n");
                return -1;
@@ -6472,7 +6548,7 @@ static int queue_function_qac_dep(struct ast_channel *chan, const char *cmd, cha
                return -1;
        }
        
-       if ((q = load_realtime_queue(data))) {
+       if ((q = find_load_queue_rt_friendly(data))) {
                ao2_lock(q);
                mem_iter = ao2_iterator_init(q->members, 0);
                while ((m = ao2_iterator_next(&mem_iter))) {
@@ -6846,8 +6922,6 @@ static void reload_single_member(const char *memberdata, struct call_queue *q)
 
        if (cur) {
                ao2_ref(cur, -1);
-       } else {
-               q->membercount++;
        }
 }
 
@@ -6863,19 +6937,11 @@ static int mark_member_dead(void *obj, void *arg, int flags)
 static int kill_dead_members(void *obj, void *arg, int flags)
 {
        struct member *member = obj;
-       struct call_queue *q = arg;
 
        if (!member->delme) {
-               if (member->dynamic) {
-                       /* dynamic members were not counted toward the member count
-                        * when reloading members from queues.conf, so we do that here
-                        */
-                       q->membercount++;
-               }
                member->status = get_queue_member_status(member);
                return 0;
        } else {
-               q->membercount--;
                return CMP_MATCH;
        }
 }
@@ -6954,7 +7020,6 @@ static void reload_single_queue(struct ast_config *cfg, struct ast_flags *mask,
                init_queue(q);
        }
        if (member_reload) {
-               q->membercount = 0;
                ao2_callback(q->members, OBJ_NODATA, mark_member_dead, NULL);
        }
        for (var = ast_variable_browse(cfg, queuename); var; var = var->next) {
@@ -7038,6 +7103,9 @@ static int reload_queues(int reload, struct ast_flags *mask, const char *queuena
                return -1;
        }
 
+       /* We've made it here, so it looks like we're doing operations on all queues. */
+       ao2_lock(queues);
+
        /* Mark all queues as dead for the moment if we're reloading queues.
         * For clarity, we could just be reloading members, in which case we don't want to mess
         * with the other queue parameters at all*/
@@ -7061,6 +7129,7 @@ static int reload_queues(int reload, struct ast_flags *mask, const char *queuena
        if (queue_reload) {
                ao2_callback(queues, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK | OBJ_NOLOCK, kill_dead_queues, (char *) queuename);
        }
+       ao2_unlock(queues);
        return 0;
 }
 
@@ -7150,7 +7219,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, const char *
        }
 
        if (argc == 3)  { /* specific queue */
-               if ((q = load_realtime_queue(argv[2]))) {
+               if ((q = find_load_queue_rt_friendly(argv[2]))) {
                        queue_t_unref(q, "Done with temporary pointer");
                }
        } else if (ast_check_realtime("queues")) {
@@ -7161,7 +7230,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, const char *
                char *queuename;
                if (cfg) {
                        for (queuename = ast_category_browse(cfg, NULL); !ast_strlen_zero(queuename); queuename = ast_category_browse(cfg, queuename)) {
-                               if ((q = load_realtime_queue(queuename))) {
+                               if ((q = find_load_queue_rt_friendly(queuename))) {
                                        queue_t_unref(q, "Done with temporary pointer");
                                }
                        }
@@ -7181,7 +7250,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, const char *
                 * been deleted from the in-core container
                 */
                if (q->realtime) {
-                       realtime_queue = load_realtime_queue(q->name);
+                       realtime_queue = find_load_queue_rt_friendly(q->name);
                        if (!realtime_queue) {
                                ao2_unlock(q);
                                queue_t_unref(q, "Done with iterator");
@@ -7253,7 +7322,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, const char *
                        do_print(s, fd, "   Callers: ");
                        for (qe = q->head; qe; qe = qe->next) {
                                ast_str_set(&out, 0, "      %d. %s (wait: %ld:%2.2ld, prio: %d)",
-                                       pos++, qe->chan->name, (long) (now - qe->start) / 60,
+                                       pos++, ast_channel_name(qe->chan), (long) (now - qe->start) / 60,
                                        (long) (now - qe->start) % 60, qe->prio);
                                do_print(s, fd, ast_str_buffer(out));
                        }
@@ -7524,7 +7593,7 @@ static int manager_queues_status(struct mansession *s, const struct message *m)
                                        "Wait: %ld\r\n"
                                        "%s"
                                        "\r\n",
-                                       q->name, pos++, qe->chan->name, qe->chan->uniqueid,
+                                       q->name, pos++, ast_channel_name(qe->chan), qe->chan->uniqueid,
                                        S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, "unknown"),
                                        S_COR(qe->chan->caller.id.name.valid, qe->chan->caller.id.name.str, "unknown"),
                                        S_COR(qe->chan->connected.id.number.valid, qe->chan->connected.id.number.str, "unknown"),
@@ -7580,9 +7649,9 @@ static int manager_add_queue_member(struct mansession *s, const struct message *
        switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface)) {
        case RES_OKAY:
                if (ast_strlen_zero(membername) || !log_membername_as_agent) {
-                       ast_queue_log(queuename, "MANAGER", interface, "ADDMEMBER", "%s", "");
+                       ast_queue_log(queuename, "MANAGER", interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
                } else {
-                       ast_queue_log(queuename, "MANAGER", membername, "ADDMEMBER", "%s", "");
+                       ast_queue_log(queuename, "MANAGER", membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
                }
                astman_send_ack(s, m, "Added interface to queue");
                break;
@@ -7619,7 +7688,7 @@ static int manager_remove_queue_member(struct mansession *s, const struct messag
 
        switch (remove_from_queue(queuename, interface)) {
        case RES_OKAY:
-               if (!mem || ast_strlen_zero(mem->membername) || !log_membername_as_agent) {
+               if (!mem || ast_strlen_zero(mem->membername)) {
                        ast_queue_log(queuename, "MANAGER", interface, "REMOVEMEMBER", "%s", "");
                } else {
                        ast_queue_log(queuename, "MANAGER", mem->membername, "REMOVEMEMBER", "%s", "");
@@ -7640,6 +7709,10 @@ static int manager_remove_queue_member(struct mansession *s, const struct messag
                break;
        }
 
+       if (mem) {
+               ao2_ref(mem, -1);
+       }
+
        return 0;
 }
 
@@ -7939,17 +8012,19 @@ static char *handle_queue_remove_member(struct ast_cli_entry *e, int cmd, struct
        queuename = a->argv[5];
        interface = a->argv[3];
 
-       if (log_membername_as_agent) {
-               mem = find_member_by_queuename_and_interface(queuename, interface);
-       }
-
        switch (remove_from_queue(queuename, interface)) {
        case RES_OKAY:
-               if (!mem || ast_strlen_zero(mem->membername) || !log_membername_as_agent) {
+               if (log_membername_as_agent) {
+                       mem = find_member_by_queuename_and_interface(queuename, interface);
+               }
+               if (!mem || ast_strlen_zero(mem->membername)) {
                        ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
                } else {
                        ast_queue_log(queuename, "CLI", mem->membername, "REMOVEMEMBER", "%s", "");
                }
+               if (mem) {
+                       ao2_ref(mem, -1);
+               }
                ast_cli(a->fd, "Removed interface %s from queue '%s'\n", interface, queuename);
                return CLI_SUCCESS;
        case RES_EXISTS:
@@ -8335,8 +8410,7 @@ static struct ast_cli_entry cli_queue[] = {
        MEMBER(call_queue, rrpos, AST_DATA_INTEGER)                     \
        MEMBER(call_queue, memberdelay, AST_DATA_INTEGER)               \
        MEMBER(call_queue, autofill, AST_DATA_INTEGER)                  \
-       MEMBER(call_queue, members, AST_DATA_CONTAINER)                 \
-       MEMBER(call_queue, membercount, AST_DATA_INTEGER)
+       MEMBER(call_queue, members, AST_DATA_CONTAINER)
 
 AST_DATA_STRUCTURE(call_queue, DATA_EXPORT_CALL_QUEUE);
 
@@ -8404,6 +8478,7 @@ static void queues_data_provider_get_helper(const struct ast_data_search *search
        ast_data_add_structure(call_queue, data_queue, queue);
 
        ast_data_add_str(data_queue, "strategy", int2strat(queue->strategy));
+       ast_data_add_int(data_queue, "membercount", ao2_container_count(queue->members));
 
        /* announce position */
        enum_node = ast_data_add_node(data_queue, "announceposition");
@@ -8505,7 +8580,7 @@ static int queues_data_provider_get(const struct ast_data_search *search,
                for (queuename = ast_category_browse(cfg, NULL);
                                !ast_strlen_zero(queuename);
                                queuename = ast_category_browse(cfg, queuename)) {
-                       if ((queue = load_realtime_queue(queuename))) {
+                       if ((queue = find_load_queue_rt_friendly(queuename))) {
                                queue_unref(queue);
                        }
                }
@@ -8517,7 +8592,7 @@ static int queues_data_provider_get(const struct ast_data_search *search,
        while ((queue = ao2_iterator_next(&i))) {
                ao2_lock(queue);
                if (queue->realtime) {
-                       queue_realtime = load_realtime_queue(queue->name);
+                       queue_realtime = find_load_queue_rt_friendly(queue->name);
                        if (!queue_realtime) {
                                ao2_unlock(queue);
                                queue_unref(queue);
@@ -8681,7 +8756,7 @@ static struct member *find_member_by_queuename_and_interface(const char *queuena
        struct member *mem = NULL;
        struct call_queue *q;
 
-       if ((q = load_realtime_queue(queuename))) {
+       if ((q = find_load_queue_rt_friendly(queuename))) {
                ao2_lock(q);
                mem = ao2_find(q->members, interface, OBJ_KEY);
                ao2_unlock(q);