mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 10:47:18 +00:00 
			
		
		
		
	Add some debug code and add a missing release
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130232 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		| @@ -40,6 +40,11 @@ struct odbc_obj { | ||||
| 	SQLHDBC  con;                   /* ODBC Connection Handle */ | ||||
| 	struct odbc_class *parent;      /* Information about the connection is protected */ | ||||
| 	struct timeval last_used; | ||||
| #ifdef DEBUG_THREADS | ||||
| 	char file[80]; | ||||
| 	char function[80]; | ||||
| 	int lineno; | ||||
| #endif | ||||
| 	unsigned int used:1; | ||||
| 	unsigned int up:1; | ||||
| 	AST_LIST_ENTRY(odbc_obj) list; | ||||
| @@ -100,7 +105,12 @@ int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt) __attribute__ (( | ||||
|  * thread which requests it.  Note that all connections should be released | ||||
|  * when the thread is done by calling odbc_release_obj(), below. | ||||
|  */ | ||||
| #ifdef DEBUG_THREADS | ||||
| struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno); | ||||
| #define ast_odbc_request_obj(a, b)	_ast_odbc_request_obj(a, b, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||||
| #else | ||||
| struct odbc_obj *ast_odbc_request_obj(const char *name, int check); | ||||
| #endif | ||||
|  | ||||
| /*!  | ||||
|  * \brief Releases an ODBC object previously allocated by odbc_request_obj() | ||||
|   | ||||
| @@ -143,6 +143,9 @@ struct odbc_cache_tables *ast_odbc_find_table(const char *database, const char * | ||||
| 	if (tableptr) { | ||||
| 		AST_RWLIST_RDLOCK(&tableptr->columns); | ||||
| 		AST_RWLIST_UNLOCK(&odbc_tables); | ||||
| 		if (obj) { | ||||
| 			ast_odbc_release_obj(obj); | ||||
| 		} | ||||
| 		return tableptr; | ||||
| 	} | ||||
|  | ||||
| @@ -579,9 +582,16 @@ static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_c | ||||
|  | ||||
| 				while ((current = ao2_iterator_next(&aoi2))) { | ||||
| 					ast_mutex_lock(¤t->lock); | ||||
| #ifdef DEBUG_THREADS | ||||
| 					ast_cli(a->fd, "    - Connection %d: %s (%s:%d %s)\n", ++count, | ||||
| 						current->used ? "in use" : | ||||
| 						current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected", | ||||
| 						current->file, current->lineno, current->function); | ||||
| #else | ||||
| 					ast_cli(a->fd, "    - Connection %d: %s\n", ++count, | ||||
| 						current->used ? "in use" : | ||||
| 						current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected"); | ||||
| #endif | ||||
| 					ast_mutex_unlock(¤t->lock); | ||||
| 					ao2_ref(current, -1); | ||||
| 				} | ||||
| @@ -631,6 +641,11 @@ void ast_odbc_release_obj(struct odbc_obj *obj) | ||||
| 	/* For pooled connections, this frees the connection to be | ||||
| 	 * reused.  For non-pooled connections, it does nothing. */ | ||||
| 	obj->used = 0; | ||||
| #ifdef DEBUG_THREADS | ||||
| 	obj->file[0] = '\0'; | ||||
| 	obj->function[0] = '\0'; | ||||
| 	obj->lineno = 0; | ||||
| #endif | ||||
| 	ao2_ref(obj, -1); | ||||
| } | ||||
|  | ||||
| @@ -639,7 +654,11 @@ int ast_odbc_backslash_is_escape(struct odbc_obj *obj) | ||||
| 	return obj->parent->backslash_is_escape; | ||||
| } | ||||
|  | ||||
| #ifdef DEBUG_THREADS | ||||
| struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno) | ||||
| #else | ||||
| struct odbc_obj *ast_odbc_request_obj(const char *name, int check) | ||||
| #endif | ||||
| { | ||||
| 	struct odbc_obj *obj = NULL; | ||||
| 	struct odbc_class *class; | ||||
| @@ -721,6 +740,12 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check) | ||||
| 	} else if (obj && obj->parent->idlecheck > 0 && ast_tvdiff_sec(ast_tvnow(), obj->last_used) > obj->parent->idlecheck) | ||||
| 		odbc_obj_connect(obj); | ||||
|  | ||||
| #if DEBUG_THREADS | ||||
| 	ast_copy_string(obj->file, file, sizeof(obj->file)); | ||||
| 	ast_copy_string(obj->function, function, sizeof(obj->function)); | ||||
| 	obj->lineno = lineno; | ||||
| #endif | ||||
|  | ||||
| 	return obj; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user