|
|
@ -1218,13 +1218,14 @@ struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags
|
|
|
|
if (obj) {
|
|
|
|
if (obj) {
|
|
|
|
ast_assert(ao2_ref(obj, 0) > 1);
|
|
|
|
ast_assert(ao2_ref(obj, 0) > 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!obj && (class->count < class->limit) &&
|
|
|
|
if (!obj && (ast_atomic_fetchadd_int(&class->count, +1) < class->limit) &&
|
|
|
|
(time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec)) {
|
|
|
|
(time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec)) {
|
|
|
|
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
|
|
|
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
|
|
|
if (!obj) {
|
|
|
|
if (!obj) {
|
|
|
|
class->count--;
|
|
|
|
class->count--;
|
|
|
|
ao2_ref(class, -1);
|
|
|
|
ao2_ref(class, -1);
|
|
|
|
ast_debug(3, "Unable to allocate object\n");
|
|
|
|
ast_debug(3, "Unable to allocate object\n");
|
|
|
|
|
|
|
|
ast_atomic_fetchadd_int(&class->count, -1);
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_assert(ao2_ref(obj, 0) == 1);
|
|
|
|
ast_assert(ao2_ref(obj, 0) == 1);
|
|
|
@ -1235,14 +1236,18 @@ struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags
|
|
|
|
if (odbc_obj_connect(obj) == ODBC_FAIL) {
|
|
|
|
if (odbc_obj_connect(obj) == ODBC_FAIL) {
|
|
|
|
ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
|
|
|
|
ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
|
|
|
|
ao2_ref(obj, -1);
|
|
|
|
ao2_ref(obj, -1);
|
|
|
|
ast_assert(ao2_ref(class, 0) > 0);
|
|
|
|
|
|
|
|
obj = NULL;
|
|
|
|
obj = NULL;
|
|
|
|
|
|
|
|
ast_assert(ao2_ref(class, 0) > 0);
|
|
|
|
|
|
|
|
ast_atomic_fetchadd_int(&class->count, -1);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
obj->used = 1;
|
|
|
|
obj->used = 1;
|
|
|
|
ao2_link(obj->parent->obj_container, obj);
|
|
|
|
ao2_link(obj->parent->obj_container, obj);
|
|
|
|
ast_atomic_fetchadd_int(&obj->parent->count, +1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* If construction fails due to the limit (or negative timecache), reverse our increment. */
|
|
|
|
|
|
|
|
if (!obj) {
|
|
|
|
|
|
|
|
ast_atomic_fetchadd_int(&class->count, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* Object is not constructed, so delete outstanding reference to class. */
|
|
|
|
/* Object is not constructed, so delete outstanding reference to class. */
|
|
|
|
ao2_ref(class, -1);
|
|
|
|
ao2_ref(class, -1);
|
|
|
|
class = NULL;
|
|
|
|
class = NULL;
|
|
|
|