2 ******************************************************************************
4 * Copyright (C) 2009, International Business Machines *
5 * Corporation and others. All Rights Reserved. *
7 ******************************************************************************
8 * file name: ucln_imp.h
10 * tab size: 8 (not used)
13 * This file contains the platform specific implementation of per-library cleanup.
18 #ifndef __UCLN_IMP_H__
19 #define __UCLN_IMP_H__
25 * Auto cleanup of ICU libraries
26 * There are several methods in per library cleanup of icu libraries:
27 * 1) Compiler/Platform based cleanup:
28 * a) Windows MSVC uses DllMain()
29 * b) GCC uses destructor function attribute
30 * c) Sun Studio, AIX VA, and HP-UX aCC uses a linker option to set the exit function
32 * 3) Implementing own automatic cleanup functions
34 * For option 1, ensure that UCLN_NO_AUTO_CLEANUP is set to 0 by using --enable-auto-cleanup
35 * configure option or by setting UCLN_NO_AUTO_CLEANUP to 0 in pwin32.h (For Visual Studio
36 * solution file builds)
37 * For option 2, follow option 1 and also define UCLN_AUTO_ATEXIT
38 * For option 3, follow option 1 and also define UCLN_AUTO_LOCAL (see below for more information)
41 #if !UCLN_NO_AUTO_CLEANUP
44 * The following declarations are for when UCLN_AUTO_LOCAL or UCLN_AUTO_ATEXIT
45 * are defined. They are commented out because they are static and will be defined
46 * later. The information is still here to provide some guidance for the developer
47 * who chooses to use UCLN_AUTO_LOCAL.
50 * Give the library an opportunity to register an automatic cleanup.
51 * This may be called more than once.
53 /*static void ucln_registerAutomaticCleanup();*/
55 * Unregister an automatic cleanup, if possible. Called from cleanup.
57 /*static void ucln_unRegisterAutomaticCleanup();*/
59 /* ------------ automatic cleanup: registration. Choose ONE ------- */
60 #if defined(UCLN_AUTO_LOCAL)
62 * 1. define UCLN_AUTO_LOCAL,
63 * 2. create ucln_local_hook.c containing implementations of
64 * static void ucln_registerAutomaticCleanup()
65 * static void ucln_unRegisterAutomaticCleanup()
67 #include "ucln_local_hook.c"
69 #elif defined(UCLN_AUTO_ATEXIT)
71 * Use the ANSI C 'atexit' function. Note that this mechanism does not
72 * guarantee the order of cleanup relative to other users of ICU!
74 static UBool gAutoCleanRegistered
= FALSE
;
76 static void ucln_atexit_handler()
78 ucln_cleanupOne(UCLN_TYPE
);
81 static void ucln_registerAutomaticCleanup()
83 if(!gAutoCleanRegistered
) {
84 gAutoCleanRegistered
= TRUE
;
85 atexit(&ucln_atexit_handler
);
89 static void ucln_unRegisterAutomaticCleanup () {
91 /* ------------end of automatic cleanup: registration. ------- */
93 #elif defined (UCLN_FINI)
95 * If UCLN_FINI is defined, it is the (versioned, etc) name of a cleanup
96 * entrypoint. Add a stub to call ucln_cleanupOne
97 * Used on AIX, Solaris, and HP-UX
99 U_CAPI
void U_EXPORT2
UCLN_FINI (void);
101 U_CAPI
void U_EXPORT2
UCLN_FINI ()
103 /* This function must be defined, if UCLN_FINI is defined, else link error. */
104 ucln_cleanupOne(UCLN_TYPE
);
106 #elif defined(__GNUC__)
107 /* GCC - use __attribute((destructor)) */
108 static void ucln_destructor() __attribute__((destructor
)) ;
110 static void ucln_destructor()
112 ucln_cleanupOne(UCLN_TYPE
);
115 /* Windows: DllMain */
116 #elif defined (U_WINDOWS)
121 /* these are from putil.c */
122 /* READ READ READ READ! Are you getting compilation errors from windows.h?
123 Any source file which includes this (ucln_imp.h) header MUST
124 be defined with language extensions ON. */
125 # define WIN32_LEAN_AND_MEAN
126 # define VC_EXTRALEAN
131 # include <windows.h>
133 * This is a stub DllMain function with icu specific process handling code.
135 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
140 case DLL_PROCESS_ATTACH
:
141 /* ICU does not trap process attach, but must pass these through properly. */
142 /* ICU specific process attach could go here */
145 case DLL_PROCESS_DETACH
:
146 /* Here is the one we actually care about. */
148 ucln_cleanupOne(UCLN_TYPE
);
152 case DLL_THREAD_ATTACH
:
153 /* ICU does not trap thread attach, but must pass these through properly. */
154 /* ICU specific thread attach could go here */
157 case DLL_THREAD_DETACH
:
158 /* ICU does not trap thread detach, but must pass these through properly. */
159 /* ICU specific thread detach could go here */
167 #endif /* UCLN_NO_AUTO_CLEANUP */
170 #error This file can only be included once.