2 ******************************************************************************
4 * Copyright (C) 2009-2011, 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 otherwise setting UCLN_NO_AUTO_CLEANUP to 0
36 * For option 2, follow option 1 and also define UCLN_AUTO_ATEXIT
37 * For option 3, follow option 1 and also define UCLN_AUTO_LOCAL (see below for more information)
40 #if !UCLN_NO_AUTO_CLEANUP
43 * The following declarations are for when UCLN_AUTO_LOCAL or UCLN_AUTO_ATEXIT
44 * are defined. They are commented out because they are static and will be defined
45 * later. The information is still here to provide some guidance for the developer
46 * who chooses to use UCLN_AUTO_LOCAL.
49 * Give the library an opportunity to register an automatic cleanup.
50 * This may be called more than once.
52 /*static void ucln_registerAutomaticCleanup();*/
54 * Unregister an automatic cleanup, if possible. Called from cleanup.
56 /*static void ucln_unRegisterAutomaticCleanup();*/
58 #ifdef UCLN_TYPE_IS_COMMON
59 # define UCLN_CLEAN_ME_UP u_cleanup()
61 # define UCLN_CLEAN_ME_UP ucln_cleanupOne(UCLN_TYPE)
64 /* ------------ automatic cleanup: registration. Choose ONE ------- */
65 #if defined(UCLN_AUTO_LOCAL)
67 * 1. define UCLN_AUTO_LOCAL,
68 * 2. create ucln_local_hook.c containing implementations of
69 * static void ucln_registerAutomaticCleanup()
70 * static void ucln_unRegisterAutomaticCleanup()
72 #include "ucln_local_hook.c"
74 #elif defined(UCLN_AUTO_ATEXIT)
76 * Use the ANSI C 'atexit' function. Note that this mechanism does not
77 * guarantee the order of cleanup relative to other users of ICU!
79 static UBool gAutoCleanRegistered
= FALSE
;
81 static void ucln_atexit_handler()
86 static void ucln_registerAutomaticCleanup()
88 if(!gAutoCleanRegistered
) {
89 gAutoCleanRegistered
= TRUE
;
90 atexit(&ucln_atexit_handler
);
94 static void ucln_unRegisterAutomaticCleanup () {
96 /* ------------end of automatic cleanup: registration. ------- */
98 #elif defined (UCLN_FINI)
100 * If UCLN_FINI is defined, it is the (versioned, etc) name of a cleanup
101 * entrypoint. Add a stub to call ucln_cleanupOne
102 * Used on AIX, Solaris, and HP-UX
104 U_CAPI
void U_EXPORT2
UCLN_FINI (void);
106 U_CAPI
void U_EXPORT2
UCLN_FINI ()
108 /* This function must be defined, if UCLN_FINI is defined, else link error. */
112 /* Windows: DllMain */
113 #elif U_PLATFORM_HAS_WIN32_API
118 /* these are from putil.c */
119 /* READ READ READ READ! Are you getting compilation errors from windows.h?
120 Any source file which includes this (ucln_imp.h) header MUST
121 be defined with language extensions ON. */
122 # define WIN32_LEAN_AND_MEAN
123 # define VC_EXTRALEAN
128 # include <windows.h>
130 * This is a stub DllMain function with icu specific process handling code.
132 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
137 case DLL_PROCESS_ATTACH
:
138 /* ICU does not trap process attach, but must pass these through properly. */
139 /* ICU specific process attach could go here */
142 case DLL_PROCESS_DETACH
:
143 /* Here is the one we actually care about. */
149 case DLL_THREAD_ATTACH
:
150 /* ICU does not trap thread attach, but must pass these through properly. */
151 /* ICU specific thread attach could go here */
154 case DLL_THREAD_DETACH
:
155 /* ICU does not trap thread detach, but must pass these through properly. */
156 /* ICU specific thread detach could go here */
163 #elif defined(__GNUC__)
164 /* GCC - use __attribute((destructor)) */
165 static void ucln_destructor() __attribute__((destructor
)) ;
167 static void ucln_destructor()
174 #endif /* UCLN_NO_AUTO_CLEANUP */
177 #error This file can only be included once.