1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 2009-2011, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
10 * file name: ucln_imp.h
12 * tab size: 8 (not used)
15 * This file contains the platform specific implementation of per-library cleanup.
20 #ifndef __UCLN_IMP_H__
21 #define __UCLN_IMP_H__
27 * Auto cleanup of ICU libraries
28 * There are several methods in per library cleanup of icu libraries:
29 * 1) Compiler/Platform based cleanup:
30 * a) Windows MSVC uses DllMain()
31 * b) GCC uses destructor function attribute
32 * c) Sun Studio, AIX VA, and HP-UX aCC uses a linker option to set the exit function
34 * 3) Implementing own automatic cleanup functions
36 * For option 1, ensure that UCLN_NO_AUTO_CLEANUP is set to 0 by using --enable-auto-cleanup
37 * configure option or by otherwise setting UCLN_NO_AUTO_CLEANUP to 0
38 * For option 2, follow option 1 and also define UCLN_AUTO_ATEXIT
39 * For option 3, follow option 1 and also define UCLN_AUTO_LOCAL (see below for more information)
42 #if !UCLN_NO_AUTO_CLEANUP
45 * The following declarations are for when UCLN_AUTO_LOCAL or UCLN_AUTO_ATEXIT
46 * are defined. They are commented out because they are static and will be defined
47 * later. The information is still here to provide some guidance for the developer
48 * who chooses to use UCLN_AUTO_LOCAL.
51 * Give the library an opportunity to register an automatic cleanup.
52 * This may be called more than once.
54 /*static void ucln_registerAutomaticCleanup();*/
56 * Unregister an automatic cleanup, if possible. Called from cleanup.
58 /*static void ucln_unRegisterAutomaticCleanup();*/
60 #ifdef UCLN_TYPE_IS_COMMON
61 # define UCLN_CLEAN_ME_UP u_cleanup()
63 # define UCLN_CLEAN_ME_UP ucln_cleanupOne(UCLN_TYPE)
66 /* ------------ automatic cleanup: registration. Choose ONE ------- */
67 #if defined(UCLN_AUTO_LOCAL)
69 * 1. define UCLN_AUTO_LOCAL,
70 * 2. create ucln_local_hook.c containing implementations of
71 * static void ucln_registerAutomaticCleanup()
72 * static void ucln_unRegisterAutomaticCleanup()
74 #include "ucln_local_hook.c"
76 #elif defined(UCLN_AUTO_ATEXIT)
78 * Use the ANSI C 'atexit' function. Note that this mechanism does not
79 * guarantee the order of cleanup relative to other users of ICU!
81 static UBool gAutoCleanRegistered = FALSE;
83 static void ucln_atexit_handler()
88 static void ucln_registerAutomaticCleanup()
90 if(!gAutoCleanRegistered) {
91 gAutoCleanRegistered = TRUE;
92 atexit(&ucln_atexit_handler);
96 static void ucln_unRegisterAutomaticCleanup () {
98 /* ------------end of automatic cleanup: registration. ------- */
100 #elif defined (UCLN_FINI)
102 * If UCLN_FINI is defined, it is the (versioned, etc) name of a cleanup
103 * entrypoint. Add a stub to call ucln_cleanupOne
104 * Used on AIX, Solaris, and HP-UX
106 U_CAPI void U_EXPORT2 UCLN_FINI (void);
108 U_CAPI void U_EXPORT2 UCLN_FINI ()
110 /* This function must be defined, if UCLN_FINI is defined, else link error. */
114 /* Windows: DllMain */
115 #elif U_PLATFORM_HAS_WIN32_API
120 /* these are from putil.c */
121 /* READ READ READ READ! Are you getting compilation errors from windows.h?
122 Any source file which includes this (ucln_imp.h) header MUST
123 be defined with language extensions ON. */
124 # define WIN32_LEAN_AND_MEAN
125 # define VC_EXTRALEAN
130 # include <windows.h>
132 * This is a stub DllMain function with icu specific process handling code.
134 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
139 case DLL_PROCESS_ATTACH:
140 /* ICU does not trap process attach, but must pass these through properly. */
141 /* ICU specific process attach could go here */
144 case DLL_PROCESS_DETACH:
145 /* Here is the one we actually care about. */
151 case DLL_THREAD_ATTACH:
152 /* ICU does not trap thread attach, but must pass these through properly. */
153 /* ICU specific thread attach could go here */
156 case DLL_THREAD_DETACH:
157 /* ICU does not trap thread detach, but must pass these through properly. */
158 /* ICU specific thread detach could go here */
165 #elif defined(__GNUC__)
166 /* GCC - use __attribute((destructor)) */
167 static void ucln_destructor() __attribute__((destructor)) ;
169 static void ucln_destructor()
176 #endif /* UCLN_NO_AUTO_CLEANUP */
179 #error This file can only be included once.