os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/uclean.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
******************************************************************************
sl@0
     3
*                                                                            *
sl@0
     4
* Copyright (C) 2001-2005, International Business Machines                   *
sl@0
     5
*                Corporation and others. All Rights Reserved.                *
sl@0
     6
*                                                                            *
sl@0
     7
******************************************************************************
sl@0
     8
*   file name:  uclean.h
sl@0
     9
*   encoding:   US-ASCII
sl@0
    10
*   tab size:   8 (not used)
sl@0
    11
*   indentation:4
sl@0
    12
*
sl@0
    13
*   created on: 2001July05
sl@0
    14
*   created by: George Rhoten
sl@0
    15
*/
sl@0
    16
sl@0
    17
#ifndef __UCLEAN_H__
sl@0
    18
#define __UCLEAN_H__
sl@0
    19
sl@0
    20
#include "unicode/utypes.h"
sl@0
    21
/**
sl@0
    22
 * \file
sl@0
    23
 * \brief C API: Initialize and clean up ICU
sl@0
    24
 */
sl@0
    25
 
sl@0
    26
/**
sl@0
    27
 *  Initialize ICU. The description further below applies to ICU 2.6 to ICU 3.4.
sl@0
    28
 *  Starting with ICU 3.4, u_init() needs not be called any more for
sl@0
    29
 *  ensuring thread safety, but it can give an indication for whether ICU
sl@0
    30
 *  can load its data. In ICU 3.4, it will try to load the converter alias table
sl@0
    31
 *  (cnvalias.icu) and give an error code if that fails.
sl@0
    32
 *  This may change in the future.
sl@0
    33
 *  <p>
sl@0
    34
 *  For ensuring the availability of necessary data, an application should
sl@0
    35
 *  open the service objects (converters, collators, etc.) that it will use
sl@0
    36
 *  and check for error codes there.
sl@0
    37
 *  <p>
sl@0
    38
 *  Documentation for ICU 2.6 to ICU 3.4:
sl@0
    39
 *  <p>
sl@0
    40
 *  This function loads and initializes data items
sl@0
    41
 *  that are required internally by various ICU functions.  Use of this explicit
sl@0
    42
 *  initialization is required in multi-threaded applications; in 
sl@0
    43
 *  single threaded apps, use is optional, but incurs little additional
sl@0
    44
 *  cost, and is thus recommended.
sl@0
    45
 *  <p>
sl@0
    46
 *  In multi-threaded applications, u_init() should be called  in the
sl@0
    47
 *  main thread before starting additional threads, or, alternatively
sl@0
    48
 *  it can be called in each individual thread once, before other ICU
sl@0
    49
 *  functions are called in that thread.  In this second scenario, the
sl@0
    50
 *  application must guarantee that the first call to u_init() happen
sl@0
    51
 *  without contention, in a single thread only.
sl@0
    52
 *  <p>
sl@0
    53
 *  If <code>u_setMemoryFunctions()</code> or 
sl@0
    54
 *  <code>u_setMutexFunctions</code> are needed (uncommon), they must be
sl@0
    55
 *  called _before_ <code>u_init()</code>.
sl@0
    56
 *  <p>
sl@0
    57
 *  Extra, repeated, or otherwise unneeded calls to u_init() do no harm,
sl@0
    58
 *  other than taking a small amount of time.
sl@0
    59
 *
sl@0
    60
 * @param status An ICU UErrorCode parameter. It must not be <code>NULL</code>.
sl@0
    61
 *    An Error will be returned if some required part of ICU data can not
sl@0
    62
 *    be loaded or initialized.
sl@0
    63
 *    The function returns immediately if the input error code indicates a
sl@0
    64
 *    failure, as usual.
sl@0
    65
 *
sl@0
    66
 * @stable ICU 2.6
sl@0
    67
 */  
sl@0
    68
U_STABLE void U_EXPORT2 
sl@0
    69
u_init(UErrorCode *status);
sl@0
    70
sl@0
    71
/**
sl@0
    72
 * Clean up the system resources, such as allocated memory or open files,
sl@0
    73
 * used in all ICU libraries. This will free/delete all memory owned by the
sl@0
    74
 * ICU libraries, and return them to their original load state. All open ICU
sl@0
    75
 * items (collators, resource bundles, converters, etc.) must be closed before
sl@0
    76
 * calling this function, otherwise ICU may not free its allocated memory
sl@0
    77
 * (e.g. close your converters and resource bundles before calling this
sl@0
    78
 * function). Generally, this function should be called once just before
sl@0
    79
 * an application exits. For applications that dynamically load and unload
sl@0
    80
 * the ICU libraries (relatively uncommon), u_cleanup() should be called
sl@0
    81
 * just before the library unload.
sl@0
    82
 * <p>
sl@0
    83
 * u_cleanup() also clears any ICU heap functions, mutex functions or
sl@0
    84
 * trace functions that may have been set for the process.  
sl@0
    85
 * This has the effect of restoring ICU to its initial condition, before
sl@0
    86
 * any of these override functions were installed.  Refer to
sl@0
    87
 * u_setMemoryFunctions(), u_setMutexFunctions and 
sl@0
    88
 * utrace_setFunctions().  If ICU is to be reinitialized after after
sl@0
    89
 * calling u_cleanup(), these runtime override functions will need to
sl@0
    90
 * be set up again if they are still required.
sl@0
    91
 * <p>
sl@0
    92
 * u_cleanup() is not thread safe.  All other threads should stop using ICU
sl@0
    93
 * before calling this function.
sl@0
    94
 * <p>
sl@0
    95
 * Any open ICU items will be left in an undefined state by u_cleanup(),
sl@0
    96
 * and any subsequent attempt to use such an item will give unpredictable
sl@0
    97
 * results.
sl@0
    98
 * <p>
sl@0
    99
 * After calling u_cleanup(), an application may continue to use ICU by
sl@0
   100
 * calling u_init().  An application must invoke u_init() first from one single
sl@0
   101
 * thread before allowing other threads call u_init().  All threads existing
sl@0
   102
 * at the time of the first thread's call to u_init() must also call
sl@0
   103
 * u_init() themselves before continuing with other ICU operations.  
sl@0
   104
 * <p>
sl@0
   105
 * The use of u_cleanup() just before an application terminates is optional,
sl@0
   106
 * but it should be called only once for performance reasons. The primary
sl@0
   107
 * benefit is to eliminate reports of memory or resource leaks originating
sl@0
   108
 * in ICU code from the results generated by heap analysis tools.
sl@0
   109
 * <p>
sl@0
   110
 * <strong>Use this function with great care!</strong>
sl@0
   111
 * </p>
sl@0
   112
 *
sl@0
   113
 * @stable ICU 2.0
sl@0
   114
 * @system
sl@0
   115
 */
sl@0
   116
U_STABLE void U_EXPORT2 
sl@0
   117
u_cleanup(void);
sl@0
   118
sl@0
   119
sl@0
   120
sl@0
   121
sl@0
   122
/**
sl@0
   123
  * An opaque pointer type that represents an ICU mutex.
sl@0
   124
  * For user-implemented mutexes, the value will typically point to a
sl@0
   125
  *  struct or object that implements the mutex.
sl@0
   126
  * @stable ICU 2.8
sl@0
   127
  * @system
sl@0
   128
  */
sl@0
   129
typedef void *UMTX;
sl@0
   130
sl@0
   131
/**
sl@0
   132
  *  Function Pointer type for a user supplied mutex initialization function.
sl@0
   133
  *  The user-supplied function will be called by ICU whenever ICU needs to create a
sl@0
   134
  *  new mutex.  The function implementation should create a mutex, and store a pointer
sl@0
   135
  *  to something that uniquely identifies the mutex into the UMTX that is supplied
sl@0
   136
  *  as a paramter.
sl@0
   137
  *  @param context user supplied value, obtained from from u_setMutexFunctions().
sl@0
   138
  *  @param mutex   Receives a pointer that identifies the new mutex.
sl@0
   139
  *                 The mutex init function must set the UMTX to a non-null value.   
sl@0
   140
  *                 Subsequent calls by ICU to lock, unlock, or destroy a mutex will 
sl@0
   141
  *                 identify the mutex by the UMTX value.
sl@0
   142
  *  @param status  Error status.  Report errors back to ICU by setting this variable
sl@0
   143
  *                 with an error code.
sl@0
   144
  *  @stable ICU 2.8
sl@0
   145
  *  @system
sl@0
   146
  */
sl@0
   147
typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX  *mutex, UErrorCode* status);
sl@0
   148
sl@0
   149
sl@0
   150
/**
sl@0
   151
  *  Function Pointer type for a user supplied mutex functions.
sl@0
   152
  *  One of the  user-supplied functions with this signature will be called by ICU
sl@0
   153
  *  whenever ICU needs to lock, unlock, or destroy a mutex.
sl@0
   154
  *  @param context user supplied value, obtained from from u_setMutexFunctions().
sl@0
   155
  *  @param mutex   specify the mutex on which to operate.
sl@0
   156
  *  @stable ICU 2.8
sl@0
   157
  *  @system
sl@0
   158
  */
sl@0
   159
typedef void U_CALLCONV UMtxFn   (const void *context, UMTX  *mutex);
sl@0
   160
sl@0
   161
sl@0
   162
/**
sl@0
   163
  *  Set the functions that ICU will use for mutex operations
sl@0
   164
  *  Use of this function is optional; by default (without this function), ICU will
sl@0
   165
  *  directly access system functions for mutex operations
sl@0
   166
  *  This function can only be used when ICU is in an initial, unused state, before
sl@0
   167
  *  u_init() has been called.
sl@0
   168
  *  This function may be used even when ICU has been built without multi-threaded
sl@0
   169
  *  support  (see ICU_USE_THREADS pre-processor variable, umutex.h)
sl@0
   170
  *  @param context This pointer value will be saved, and then (later) passed as
sl@0
   171
  *                 a parameter to the user-supplied mutex functions each time they
sl@0
   172
  *                 are called. 
sl@0
   173
  *  @param init    Pointer to a mutex initialization function.  Must be non-null.
sl@0
   174
  *  @param destroy Pointer to the mutex destroy function.  Must be non-null.
sl@0
   175
  *  @param lock    pointer to the mutex lock function.  Must be non-null.
sl@0
   176
  *  @param unlock  Pointer to the mutex unlock function.  Must be non-null.
sl@0
   177
  *  @param status  Receives error values.
sl@0
   178
  *  @stable ICU 2.8
sl@0
   179
  *  @system
sl@0
   180
  */  
sl@0
   181
U_STABLE void U_EXPORT2 
sl@0
   182
u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock,
sl@0
   183
                    UErrorCode *status);
sl@0
   184
sl@0
   185
sl@0
   186
/**
sl@0
   187
  *  Pointer type for a user supplied atomic increment or decrement function.
sl@0
   188
  *  @param context user supplied value, obtained from from u_setAtomicIncDecFunctions().
sl@0
   189
  *  @param p   Pointer to a 32 bit int to be incremented or decremented
sl@0
   190
  *  @return    The value of the variable after the inc or dec operation.
sl@0
   191
  *  @stable ICU 2.8
sl@0
   192
  *  @system
sl@0
   193
  */
sl@0
   194
typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p);
sl@0
   195
sl@0
   196
/**
sl@0
   197
 *  Set the functions that ICU will use for atomic increment and decrement of int32_t values.
sl@0
   198
 *  Use of this function is optional; by default (without this function), ICU will
sl@0
   199
 *  use its own internal implementation of atomic increment/decrement.
sl@0
   200
 *  This function can only be used when ICU is in an initial, unused state, before
sl@0
   201
 *  u_init() has been called.
sl@0
   202
 *  @param context This pointer value will be saved, and then (later) passed as
sl@0
   203
 *                 a parameter to the increment and decrement functions each time they
sl@0
   204
 *                 are called.  This function can only be called 
sl@0
   205
 *  @param inc     Pointer to a function to do an atomic increment operation.  Must be non-null.
sl@0
   206
 *  @param dec     Pointer to a function to do an atomic decrement operation.  Must be non-null.
sl@0
   207
 *  @param status  Receives error values.
sl@0
   208
 *  @stable ICU 2.8
sl@0
   209
 *  @system
sl@0
   210
 */  
sl@0
   211
U_STABLE void U_EXPORT2 
sl@0
   212
u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec,
sl@0
   213
                    UErrorCode *status);
sl@0
   214
sl@0
   215
sl@0
   216
sl@0
   217
/**
sl@0
   218
  *  Pointer type for a user supplied memory allocation function.
sl@0
   219
  *  @param context user supplied value, obtained from from u_setMemoryFunctions().
sl@0
   220
  *  @param size    The number of bytes to be allocated
sl@0
   221
  *  @return        Pointer to the newly allocated memory, or NULL if the allocation failed.
sl@0
   222
  *  @stable ICU 2.8
sl@0
   223
  *  @system
sl@0
   224
  */
sl@0
   225
typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size);
sl@0
   226
/**
sl@0
   227
  *  Pointer type for a user supplied memory re-allocation function.
sl@0
   228
  *  @param context user supplied value, obtained from from u_setMemoryFunctions().
sl@0
   229
  *  @param size    The number of bytes to be allocated
sl@0
   230
  *  @return        Pointer to the newly allocated memory, or NULL if the allocation failed.
sl@0
   231
  *  @stable ICU 2.8
sl@0
   232
  *  @system
sl@0
   233
  */
sl@0
   234
typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size);
sl@0
   235
/**
sl@0
   236
  *  Pointer type for a user supplied memory free  function.  Behavior should be
sl@0
   237
  *  similar the standard C library free().
sl@0
   238
  *  @param context user supplied value, obtained from from u_setMemoryFunctions().
sl@0
   239
  *  @param mem     Pointer to the memory block to be resized
sl@0
   240
  *  @param size    The new size for the block
sl@0
   241
  *  @return        Pointer to the resized memory block, or NULL if the resizing failed.
sl@0
   242
  *  @stable ICU 2.8
sl@0
   243
  *  @system
sl@0
   244
  */
sl@0
   245
typedef void  U_CALLCONV UMemFreeFn (const void *context, void *mem);
sl@0
   246
sl@0
   247
/**
sl@0
   248
 *  Set the functions that ICU will use for memory allocation.
sl@0
   249
 *  Use of this function is optional; by default (without this function), ICU will
sl@0
   250
 *  use the standard C library malloc() and free() functions.
sl@0
   251
 *  This function can only be used when ICU is in an initial, unused state, before
sl@0
   252
 *  u_init() has been called.
sl@0
   253
 *  @param context This pointer value will be saved, and then (later) passed as
sl@0
   254
 *                 a parameter to the memory functions each time they
sl@0
   255
 *                 are called.
sl@0
   256
 *  @param a       Pointer to a user-supplied malloc function.
sl@0
   257
 *  @param r       Pointer to a user-supplied realloc function.
sl@0
   258
 *  @param f       Pointer to a user-supplied free function.
sl@0
   259
 *  @param status  Receives error values.
sl@0
   260
 *  @stable ICU 2.8
sl@0
   261
 *  @system
sl@0
   262
 */  
sl@0
   263
U_STABLE void U_EXPORT2 
sl@0
   264
u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, 
sl@0
   265
                    UErrorCode *status);
sl@0
   266
sl@0
   267
#endif