summaryrefslogtreecommitdiff
path: root/src/env/env_handle.c
blob: 7a7f187b574dce9697b90e1b606117e3296a60ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2008-2011 WiredTiger, Inc.
 *	All rights reserved.
 */

#include "wt_internal.h"

/*
 * __wt_connection_config --
 *	Set configuration for a just-created CONNECTION handle.
 */
int
__wt_connection_config(CONNECTION *conn)
{
	SESSION *session;

	session = &conn->default_session;

	__wt_methods_connection_config_default(conn);
	__wt_methods_connection_lockout(conn);
	__wt_methods_connection_init_transition(conn);

						/* Global mutex */
	WT_RET(__wt_mtx_alloc(session, "CONNECTION", 0, &conn->mtx));

	TAILQ_INIT(&conn->dbqh);		/* BTREE list */
	TAILQ_INIT(&conn->fhqh);		/* File list */

	/* Statistics. */
	WT_RET(__wt_stat_alloc_conn_stats(session, &conn->stats));

	/* Diagnostic output separator. */
	conn->sep = "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=";

	return (0);
}

/*
 * __wt_connection_destroy --
 *	Destroy the CONNECTION's underlying CONNECTION structure.
 */
int
__wt_connection_destroy(CONNECTION *conn)
{
	SESSION *session;
	int ret;

	session = &conn->default_session;
	ret = 0;

	/* Check there's something to destroy. */
	if (conn == NULL)
		return (0);

	/* Diagnostic check: check flags against approved list. */
	WT_CONN_FCHK_RET(conn, "Env.close", conn->flags, WT_APIMASK_CONN, ret);

	if (conn->mtx != NULL)
		(void)__wt_mtx_destroy(session, conn->mtx);

	/* Free allocated memory. */
	__wt_free(session, conn->home);
	__wt_free(session, conn->sessions);
	__wt_free(session, conn->toc_array);
	__wt_free(session, conn->hazard);
	__wt_free(session, conn->stats);

	__wt_free(NULL, conn);
	return (ret);
}