intl/icu/source/common/ucln_imp.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/ucln_imp.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +* Copyright (C) 2009-2011, International Business Machines
     1.8 +*                Corporation and others. All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*   file name:  ucln_imp.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   This file contains the platform specific implementation of per-library cleanup.
    1.17 +*
    1.18 +*/
    1.19 +
    1.20 +
    1.21 +#ifndef __UCLN_IMP_H__
    1.22 +#define __UCLN_IMP_H__
    1.23 +
    1.24 +#include "ucln.h"
    1.25 +#include <stdlib.h>
    1.26 +
    1.27 +/**
    1.28 + * Auto cleanup of ICU libraries
    1.29 + * There are several methods in per library cleanup of icu libraries:
    1.30 + * 1) Compiler/Platform based cleanup:
    1.31 + *   a) Windows MSVC uses DllMain()
    1.32 + *   b) GCC uses destructor function attribute
    1.33 + *   c) Sun Studio, AIX VA, and HP-UX aCC uses a linker option to set the exit function
    1.34 + * 2) Using atexit()
    1.35 + * 3) Implementing own automatic cleanup functions
    1.36 + *
    1.37 + * For option 1, ensure that UCLN_NO_AUTO_CLEANUP is set to 0 by using --enable-auto-cleanup
    1.38 + * configure option or by otherwise setting UCLN_NO_AUTO_CLEANUP to 0
    1.39 + * For option 2, follow option 1 and also define UCLN_AUTO_ATEXIT
    1.40 + * For option 3, follow option 1 and also define UCLN_AUTO_LOCAL (see below for more information)
    1.41 + */
    1.42 +
    1.43 +#if !UCLN_NO_AUTO_CLEANUP
    1.44 +
    1.45 +/*
    1.46 + * The following declarations are for when UCLN_AUTO_LOCAL or UCLN_AUTO_ATEXIT
    1.47 + * are defined. They are commented out because they are static and will be defined
    1.48 + * later. The information is still here to provide some guidance for the developer
    1.49 + * who chooses to use UCLN_AUTO_LOCAL.
    1.50 + */
    1.51 +/**
    1.52 + * Give the library an opportunity to register an automatic cleanup.
    1.53 + * This may be called more than once.
    1.54 + */
    1.55 +/*static void ucln_registerAutomaticCleanup();*/
    1.56 +/**
    1.57 + * Unregister an automatic cleanup, if possible. Called from cleanup.
    1.58 + */
    1.59 +/*static void ucln_unRegisterAutomaticCleanup();*/
    1.60 +
    1.61 +#ifdef UCLN_TYPE_IS_COMMON
    1.62 +#   define UCLN_CLEAN_ME_UP u_cleanup()
    1.63 +#else
    1.64 +#   define UCLN_CLEAN_ME_UP ucln_cleanupOne(UCLN_TYPE)
    1.65 +#endif
    1.66 +
    1.67 +/* ------------ automatic cleanup: registration. Choose ONE ------- */
    1.68 +#if defined(UCLN_AUTO_LOCAL)
    1.69 +/* To use:
    1.70 + *  1. define UCLN_AUTO_LOCAL,
    1.71 + *  2. create ucln_local_hook.c containing implementations of
    1.72 + *           static void ucln_registerAutomaticCleanup()
    1.73 + *           static void ucln_unRegisterAutomaticCleanup()
    1.74 + */
    1.75 +#include "ucln_local_hook.c"
    1.76 +
    1.77 +#elif defined(UCLN_AUTO_ATEXIT)
    1.78 +/*
    1.79 + * Use the ANSI C 'atexit' function. Note that this mechanism does not
    1.80 + * guarantee the order of cleanup relative to other users of ICU!
    1.81 + */
    1.82 +static UBool gAutoCleanRegistered = FALSE;
    1.83 +
    1.84 +static void ucln_atexit_handler()
    1.85 +{
    1.86 +    UCLN_CLEAN_ME_UP;
    1.87 +}
    1.88 +
    1.89 +static void ucln_registerAutomaticCleanup()
    1.90 +{
    1.91 +    if(!gAutoCleanRegistered) {
    1.92 +        gAutoCleanRegistered = TRUE;
    1.93 +        atexit(&ucln_atexit_handler);
    1.94 +    }
    1.95 +}
    1.96 +
    1.97 +static void ucln_unRegisterAutomaticCleanup () {
    1.98 +}
    1.99 +/* ------------end of automatic cleanup: registration. ------- */
   1.100 +
   1.101 +#elif defined (UCLN_FINI)
   1.102 +/**
   1.103 + * If UCLN_FINI is defined, it is the (versioned, etc) name of a cleanup
   1.104 + * entrypoint. Add a stub to call ucln_cleanupOne
   1.105 + * Used on AIX, Solaris, and HP-UX
   1.106 + */
   1.107 +U_CAPI void U_EXPORT2 UCLN_FINI (void);
   1.108 +
   1.109 +U_CAPI void U_EXPORT2 UCLN_FINI ()
   1.110 +{
   1.111 +    /* This function must be defined, if UCLN_FINI is defined, else link error. */
   1.112 +     UCLN_CLEAN_ME_UP;
   1.113 +}
   1.114 +
   1.115 +/* Windows: DllMain */
   1.116 +#elif U_PLATFORM_HAS_WIN32_API
   1.117 +/* 
   1.118 + * ICU's own DllMain.
   1.119 + */
   1.120 +
   1.121 +/* these are from putil.c */
   1.122 +/* READ READ READ READ!    Are you getting compilation errors from windows.h?
   1.123 +          Any source file which includes this (ucln_imp.h) header MUST 
   1.124 +          be defined with language extensions ON. */
   1.125 +#   define WIN32_LEAN_AND_MEAN
   1.126 +#   define VC_EXTRALEAN
   1.127 +#   define NOUSER
   1.128 +#   define NOSERVICE
   1.129 +#   define NOIME
   1.130 +#   define NOMCX
   1.131 +#   include <windows.h>
   1.132 +/*
   1.133 + * This is a stub DllMain function with icu specific process handling code.
   1.134 + */
   1.135 +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
   1.136 +{
   1.137 +    BOOL status = TRUE;
   1.138 +
   1.139 +    switch(fdwReason) {
   1.140 +        case DLL_PROCESS_ATTACH:
   1.141 +             /* ICU does not trap process attach, but must pass these through properly. */
   1.142 +            /* ICU specific process attach could go here */
   1.143 +            break;
   1.144 +
   1.145 +        case DLL_PROCESS_DETACH:
   1.146 +            /* Here is the one we actually care about. */
   1.147 +
   1.148 +            UCLN_CLEAN_ME_UP;
   1.149 +
   1.150 +            break;
   1.151 +
   1.152 +        case DLL_THREAD_ATTACH:
   1.153 +            /* ICU does not trap thread attach, but must pass these through properly. */
   1.154 +            /* ICU specific thread attach could go here */
   1.155 +            break;
   1.156 +
   1.157 +        case DLL_THREAD_DETACH:
   1.158 +            /* ICU does not trap thread detach, but must pass these through properly. */
   1.159 +            /* ICU specific thread detach could go here */
   1.160 +            break;
   1.161 +
   1.162 +    }
   1.163 +    return status;
   1.164 +}
   1.165 +
   1.166 +#elif defined(__GNUC__)
   1.167 +/* GCC - use __attribute((destructor)) */
   1.168 +static void ucln_destructor()   __attribute__((destructor)) ;
   1.169 +
   1.170 +static void ucln_destructor() 
   1.171 +{
   1.172 +    UCLN_CLEAN_ME_UP;
   1.173 +}
   1.174 +
   1.175 +#endif
   1.176 +
   1.177 +#endif /* UCLN_NO_AUTO_CLEANUP */
   1.178 +
   1.179 +#else
   1.180 +#error This file can only be included once.
   1.181 +#endif

mercurial