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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*-
* Copyright (c) 2008-2013 WiredTiger, Inc.
* All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
#include "wt_internal.h"
/*
* __wt_connection_init --
* Structure initialization for a just-created WT_CONNECTION_IMPL handle.
*/
int
__wt_connection_init(WT_CONNECTION_IMPL *conn)
{
WT_SESSION_IMPL *session;
session = conn->default_session;
TAILQ_INIT(&conn->btqh); /* WT_BTREE list */
TAILQ_INIT(&conn->dlhqh); /* Library list */
TAILQ_INIT(&conn->dsrcqh); /* Data source list */
TAILQ_INIT(&conn->fhqh); /* File list */
TAILQ_INIT(&conn->collqh); /* Collator list */
TAILQ_INIT(&conn->compqh); /* Compressor list */
TAILQ_INIT(&conn->lsmqh); /* WT_LSM_TREE list */
/* Statistics. */
WT_RET(__wt_stat_alloc_connection_stats(session, &conn->stats));
/* Locks. */
__wt_spin_init(session, &conn->api_lock);
__wt_spin_init(session, &conn->fh_lock);
__wt_spin_init(session, &conn->metadata_lock);
__wt_spin_init(session, &conn->schema_lock);
__wt_spin_init(session, &conn->serial_lock);
return (0);
}
/*
* __wt_connection_destroy --
* Destroy the connection's underlying WT_CONNECTION_IMPL structure.
*/
int
__wt_connection_destroy(WT_CONNECTION_IMPL *conn)
{
WT_DECL_RET;
WT_SESSION_IMPL *session;
session = conn->default_session;
/* Check there's something to destroy. */
if (conn == NULL)
return (0);
/*
* Close remaining open files (before discarding the mutex, the
* underlying file-close code uses the mutex to guard lists of
* open files.
*/
if (conn->lock_fh != NULL)
WT_TRET(__wt_close(session, conn->lock_fh));
if (conn->log_fh != NULL)
WT_TRET(__wt_close(session, conn->log_fh));
/* Remove from the list of connections. */
__wt_spin_lock(session, &__wt_process.spinlock);
TAILQ_REMOVE(&__wt_process.connqh, conn, q);
__wt_spin_unlock(session, &__wt_process.spinlock);
__wt_spin_destroy(session, &conn->api_lock);
__wt_spin_destroy(session, &conn->fh_lock);
__wt_spin_destroy(session, &conn->metadata_lock);
__wt_spin_destroy(session, &conn->schema_lock);
__wt_spin_destroy(session, &conn->serial_lock);
/* Free allocated memory. */
__wt_free(session, conn->home);
__wt_free(session, conn->sessions);
__wt_free(session, conn->stats);
__wt_free(NULL, conn);
return (ret);
}
|