Index: app_meetme.c =================================================================== --- app_meetme.c (revision 59193) +++ app_meetme.c (working copy) @@ -513,6 +513,11 @@ .thread = AST_PTHREADT_NULL, }; +/*! map of being used conference numbers. */ +static int conf_map[1024] = { 0, }; +/*! conf_map mutex lock */ +AST_MUTEX_DEFINE_STATIC(conf_map_lock); + /*! The number of audio buffers to be allocated on pseudo channels * when in a conference */ static int audio_buffers; @@ -720,7 +725,7 @@ { struct ast_conference *cnf; struct zt_confinfo ztc = { 0, }; - + int confno_int = 0; AST_LIST_LOCK(&confs); AST_LIST_TRAVERSE(&confs, cnf, list) { @@ -780,7 +785,10 @@ cnfout: if (cnf) ast_atomic_fetchadd_int(&cnf->refcount, refcount); - + ast_mutex_lock(&conf_map_lock); + sscanf(confno, "%d", &confno_int); + conf_map[confno_int]++; + ast_mutex_unlock(&conf_map_lock); AST_LIST_UNLOCK(&confs); return cnf; @@ -1312,12 +1320,18 @@ static int dispose_conf(struct ast_conference *conf) { int res = 0; + int confno_int = 0; AST_LIST_LOCK(&confs); if (ast_atomic_dec_and_test(&conf->refcount)) { conf_free(conf); res = 1; } + /* free conf_map usage */ + ast_mutex_lock(&conf_map_lock); + sscanf(conf->confno, "%d", &confno_int); + conf_map[confno_int] = 0; + ast_mutex_unlock(&conf_map_lock); AST_LIST_UNLOCK(&confs); return res; @@ -2521,21 +2535,11 @@ if (retrycnt > 3) allowretry = 0; if (empty) { - int i, map[1024] = { 0, }; + int i; struct ast_config *cfg; struct ast_variable *var; int confno_int; - - AST_LIST_LOCK(&confs); - AST_LIST_TRAVERSE(&confs, cnf, list) { - if (sscanf(cnf->confno, "%d", &confno_int) == 1) { - /* Disqualify in use conference */ - if (confno_int >= 0 && confno_int < 1024) - map[confno_int]++; - } - } - AST_LIST_UNLOCK(&confs); - + /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */ if ((empty_no_pin) || (!dynamic)) { cfg = ast_config_load(CONFIG_FILE_NAME); @@ -2547,13 +2551,6 @@ if (stringp) { char *confno_tmp = strsep(&stringp, "|,"); int found = 0; - if (sscanf(confno_tmp, "%d", &confno_int) == 1) { - if ((confno_int >= 0) && (confno_int < 1024)) { - if (stringp && empty_no_pin) { - map[confno_int]++; - } - } - } if (!dynamic) { /* For static: run through the list and see if this conference is empty */ AST_LIST_LOCK(&confs); @@ -2588,12 +2585,15 @@ /* Select first conference number not in use */ if (ast_strlen_zero(confno) && dynamic) { - for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) { - if (!map[i]) { + ast_mutex_lock(&conf_map_lock); + for (i = 0; i < sizeof(conf_map) / sizeof(conf_map[0]); i++) { + if (!conf_map[i]) { snprintf(confno, sizeof(confno), "%d", i); + conf_map[i]++; break; } } + ast_mutex_unlock(&conf_map_lock); } /* Not found? */