Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / udapl / libdat / common / dat_init.c
blobd706c505e6ccedbc9c089324c8b1576d0fd1e924
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
36 * MODULE: dat_init.c
38 * PURPOSE: DAT registry implementation for uDAPL
39 * Description: init and fini functions for DAT module.
41 * $Id: dat_init.c,v 1.12 2003/07/09 11:26:06 hobie16 Exp $
44 #include "dat_init.h"
46 #include "dat_dr.h"
47 #include "dat_osd.h"
49 #ifndef DAT_NO_STATIC_REGISTRY
50 #include "dat_sr.h"
51 #endif
56 * Global Variables
61 * Ideally, the following two rules could be enforced:
63 * - The DAT Registry's initialization function is executed before that
64 * of any DAT Providers and hence all calls into the registry occur
65 * after the registry module is initialized.
67 * - The DAT Registry's deinitialization function is executed after that
68 * of any DAT Providers and hence all calls into the registry occur
69 * before the registry module is deinitialized.
71 * However, on many platforms few guarantees are provided regarding the
72 * order in which modules initialization and deinitialization functions
73 * are invoked.
75 * To understand why these rules are difficult to enforce using only
76 * features common to all platforms, consider the Linux platform. The order
77 * in which Linux shared libraries are loaded into a process's address space
78 * is undefined. When a DAT consumer explicitly links to DAT provider
79 * libraries, the order in which library initialization and deinitialization
80 * functions are invoked becomes important. For example if the DAPL provider
81 * calls dat_registry_add_provider() before the registry has been initialized,
82 * an error will occur.
84 * We assume that modules are loaded with a single thread. Given
85 * this assumption, we can use a simple state variable to determine
86 * the state of the DAT registry.
89 static DAT_MODULE_STATE g_module_state = DAT_MODULE_STATE_UNINITIALIZED;
93 * Function: dat_module_get_state
96 DAT_MODULE_STATE
97 dat_module_get_state(void)
99 return (g_module_state);
104 * Function: dat_init
107 void
108 dat_init(void)
110 if (DAT_MODULE_STATE_UNINITIALIZED == g_module_state) {
112 * update the module state flag immediately in case there
113 * is a recursive call to dat_init().
115 g_module_state = DAT_MODULE_STATE_INITIALIZING;
117 dat_os_dbg_init();
119 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
120 "DAT Registry: Started (dat_init)\n");
122 #ifndef DAT_NO_STATIC_REGISTRY
123 (void) dat_sr_init();
124 #endif
125 (void) dat_dr_init();
127 g_module_state = DAT_MODULE_STATE_INITIALIZED;
133 * Function: dat_fini
136 void
137 dat_fini(void)
139 if (DAT_MODULE_STATE_INITIALIZED == g_module_state) {
140 g_module_state = DAT_MODULE_STATE_DEINITIALIZING;
142 (void) dat_dr_fini();
143 #ifndef DAT_NO_STATIC_REGISTRY
144 (void) dat_sr_fini();
145 #endif
146 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
147 "DAT Registry: Stopped (dat_fini)\n");
149 g_module_state = DAT_MODULE_STATE_DEINITIALIZED;
155 * Local variables:
156 * c-indent-level: 4
157 * c-basic-offset: 4
158 * tab-width: 8
159 * End: