os/textandloc/fontservices/textshaperplugin/IcuSource/common/umutex.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/umutex.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,143 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +*   Copyright (C) 1997-2005, International Business Machines
     1.7 +*   Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +*
    1.10 +* File UMUTEX.H
    1.11 +*
    1.12 +* Modification History:
    1.13 +*
    1.14 +*   Date        Name        Description
    1.15 +*   04/02/97  aliu        Creation.
    1.16 +*   04/07/99  srl         rewrite - C interface, multiple mutices
    1.17 +*   05/13/99  stephen     Changed to umutex (from cmutex)
    1.18 +******************************************************************************
    1.19 +*/
    1.20 +
    1.21 +#ifndef UMUTEX_H
    1.22 +#define UMUTEX_H
    1.23 +
    1.24 +#include "unicode/utypes.h"
    1.25 +#include "unicode/uclean.h"  
    1.26 +
    1.27 +
    1.28 +/* APP_NO_THREADS is an old symbol. We'll honour it if present. */
    1.29 +#ifdef APP_NO_THREADS
    1.30 +# define ICU_USE_THREADS 0
    1.31 +#endif
    1.32 +
    1.33 +/* ICU_USE_THREADS
    1.34 + *
    1.35 + *   Allows thread support (use of mutexes) to be compiled out of ICU.
    1.36 + *   Default: use threads.
    1.37 + *   Even with thread support compiled out, applications may override the
    1.38 + *   (empty) mutex implementation with the u_setMutexFunctions() functions.
    1.39 + */ 
    1.40 +#ifndef ICU_USE_THREADS
    1.41 +# define ICU_USE_THREADS 1
    1.42 +#endif
    1.43 +
    1.44 +/**
    1.45 + * By default assume that we are on a machine with a weak memory model,
    1.46 + * and the double check lock won't work reliably.
    1.47 + */
    1.48 +#if !defined(UMTX_STRONG_MEMORY_MODEL)
    1.49 +#define UMTX_STRONG_MEMORY_MODEL 0
    1.50 +#endif
    1.51 +
    1.52 +/**
    1.53 + * \def UMTX_CHECK
    1.54 + * Encapsulates a safe check for an expression (usually a condition)
    1.55 + * for lazy variable inititialization.
    1.56 + * On CPUs with weak memory models, this must use memory fence instructions
    1.57 + * or mutexes.
    1.58 + * @internal
    1.59 + */
    1.60 +#if UMTX_STRONG_MEMORY_MODEL
    1.61 +
    1.62 +#define UMTX_CHECK(pMutex, expression, result) \
    1.63 +    (result)=(expression);
    1.64 +
    1.65 +#else
    1.66 +
    1.67 +#define UMTX_CHECK(pMutex, expression, result) \
    1.68 +    umtx_lock(pMutex); \
    1.69 +    (result)=(expression); \
    1.70 +    umtx_unlock(pMutex);
    1.71 +
    1.72 +#endif
    1.73 +
    1.74 +/*
    1.75 + * Code within ICU that accesses shared static or global data should
    1.76 + * instantiate a Mutex object while doing so.  The unnamed global mutex
    1.77 + * is used throughout ICU, so keep locking short and sweet.
    1.78 + *
    1.79 + * For example:
    1.80 + *
    1.81 + * void Function(int arg1, int arg2)
    1.82 + * {
    1.83 + *   static Object* foo;     // Shared read-write object
    1.84 + *   umtx_lock(NULL);        // Lock the ICU global mutex
    1.85 + *   foo->Method();
    1.86 + *   umtx_unlock(NULL);
    1.87 + * }
    1.88 + *
    1.89 + * an alternative C++ mutex API is defined in the file common/mutex.h
    1.90 + */
    1.91 +
    1.92 +/* Lock a mutex. 
    1.93 + * @param mutex The given mutex to be locked.  Pass NULL to specify
    1.94 + *              the global ICU mutex.  Recursive locks are an error
    1.95 + *              and may cause a deadlock on some platforms.
    1.96 + */
    1.97 +U_CAPI void U_EXPORT2 umtx_lock   ( UMTX* mutex ); 
    1.98 +
    1.99 +/* Unlock a mutex. Pass in NULL if you want the single global
   1.100 +   mutex. 
   1.101 + * @param mutex The given mutex to be unlocked.  Pass NULL to specify
   1.102 + *              the global ICU mutex.
   1.103 + */
   1.104 +U_CAPI void U_EXPORT2 umtx_unlock ( UMTX* mutex );
   1.105 +
   1.106 +/* Initialize a mutex. Use it this way:
   1.107 +   umtx_init( &aMutex ); 
   1.108 + * ICU Mutexes do not need explicit initialization before use.  Use of this
   1.109 + *   function is not necessary.
   1.110 + * Initialization of an already initialized mutex has no effect, and is safe to do.
   1.111 + * Initialization of mutexes is thread safe.  Two threads can concurrently 
   1.112 + *   initialize the same mutex without causing problems.
   1.113 + * @param mutex The given mutex to be initialized
   1.114 + */
   1.115 +U_CAPI void U_EXPORT2 umtx_init   ( UMTX* mutex );
   1.116 +
   1.117 +/* Destroy a mutex. This will free the resources of a mutex.
   1.118 + * Use it this way:
   1.119 + *   umtx_destroy( &aMutex ); 
   1.120 + * Destroying an already destroyed mutex has no effect, and causes no problems.
   1.121 + * This function is not thread safe.  Two threads must not attempt to concurrently
   1.122 + *   destroy the same mutex.
   1.123 + * @param mutex The given mutex to be destroyed.
   1.124 + */
   1.125 +U_CAPI void U_EXPORT2 umtx_destroy( UMTX *mutex );
   1.126 +
   1.127 +
   1.128 +
   1.129 +/*
   1.130 + * Atomic Increment and Decrement of an int32_t value.
   1.131 + *
   1.132 + * Return Values:
   1.133 + *   If the result of the operation is zero, the return zero.
   1.134 + *   If the result of the operation is not zero, the sign of returned value
   1.135 + *      is the same as the sign of the result, but the returned value itself may
   1.136 + *      be different from the result of the operation.
   1.137 + */
   1.138 +U_CAPI int32_t U_EXPORT2 umtx_atomic_inc(int32_t *);
   1.139 +U_CAPI int32_t U_EXPORT2 umtx_atomic_dec(int32_t *);
   1.140 +
   1.141 +
   1.142 +#endif /*_CMUTEX*/
   1.143 +/*eof*/
   1.144 +
   1.145 +
   1.146 +