Debian Codegraph @

dat/common/dat_init.c

raw
1 /*
2 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under one of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistributions of source code must retain the above copyright
24 * notice and one of the license notices.
25 *
26 * Redistributions in binary form must reproduce both the above copyright
27 * notice, one of the license notices in the documentation
28 * and/or other materials provided with the distribution.
29 */
30
31 /**********************************************************************
32 *
33 * MODULE: dat_init.c
34 *
35 * PURPOSE: DAT registry implementation for uDAPL
36 * Description: init and fini functions for DAT module.
37 *
38 * $Id: dat_init.c,v 1.18 2005/03/24 05:58:27 jlentini Exp $
39 **********************************************************************/
40
41 #include <dat2/dat_platform_specific.h>
42 #include "dat_init.h"
43 #include "dat_dr.h"
44 #include "dat_osd.h"
45
46 #ifndef DAT_NO_STATIC_REGISTRY
47 #include "dat_sr.h"
48 #endif
49
50 /*********************************************************************
51 * *
52 * Global Variables *
53 * *
54 *********************************************************************/
55
56 /*
57 * Ideally, the following two rules could be enforced:
58 *
59 * - The DAT Registry's initialization function is executed before that
60 * of any DAT Providers and hence all calls into the registry occur
61 * after the registry module is initialized.
62 *
63 * - The DAT Registry's deinitialization function is executed after that
64 * of any DAT Providers and hence all calls into the registry occur
65 * before the registry module is deinitialized.
66 *
67 * However, on many platforms few guarantees are provided regarding the
68 * order in which module initialization and deinitialization functions
69 * are invoked.
70 *
71 * To understand why these rules are difficult to enforce using only
72 * features common to all platforms, consider the Linux platform. The order
73 * in which Linux shared libraries are loaded into a process's address space
74 * is undefined. When a DAT consumer explicitly links to DAT provider
75 * libraries, the order in which library initialization and deinitialization
76 * functions are invoked becomes important. In this scenario, a DAPL provider
77 * may call dat_registry_add_provider() before the registry has been
78 * initialized.
79 *
80 * We assume that modules are loaded with a single thread. Given
81 * this assumption, we can use a simple state variable to determine
82 * the state of the DAT registry.
83 */
84
85 static DAT_MODULE_STATE g_module_state = DAT_MODULE_STATE_UNINITIALIZED;
86
87 //***********************************************************************
88 // Function: dat_module_get_state
89 //***********************************************************************
90
91 DAT_MODULE_STATE dat_module_get_state(void)
92 {
93 return g_module_state;
94 }
95
96 //***********************************************************************
97 // Function: dat_init
98 //***********************************************************************
99
100 void dat_init(void)
101 {
102 if (DAT_MODULE_STATE_UNINITIALIZED == g_module_state) {
103 /*
104 * update the module state flag immediately in case there
105 * is a recursive call to dat_init().
106 */
107 g_module_state = DAT_MODULE_STATE_INITIALIZING;
108
109 dat_os_dbg_init();
110
111 dats_handle_vector_init();
112
113 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
114 "DAT Registry: Started (dat_init)\n");
115
116 #ifndef DAT_NO_STATIC_REGISTRY
117 dat_sr_init();
118 #endif
119 dat_dr_init();
120
121 g_module_state = DAT_MODULE_STATE_INITIALIZED;
122 }
123 }
124
125 //***********************************************************************
126 // Function: dat_fini
127 //***********************************************************************
128
129 void dat_fini(void)
130 {
131 if (DAT_MODULE_STATE_INITIALIZED == g_module_state) {
132 g_module_state = DAT_MODULE_STATE_DEINITIALIZING;
133
134 dat_dr_fini();
135 #ifndef DAT_NO_STATIC_REGISTRY
136 dat_sr_fini();
137 #endif
138
139 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
140 "DAT Registry: Stopped (dat_fini)\n");
141
142 g_module_state = DAT_MODULE_STATE_DEINITIALIZED;
143 }
144 }
145
146 /*
147 * Local variables:
148 * c-indent-level: 4
149 * c-basic-offset: 4
150 * tab-width: 8
151 * End:
152 */