1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-12-09 23:27:55 +00:00
|
|
|
**********************************************************************
|
2001-03-21 20:44:20 +00:00
|
|
|
* Copyright (C) 1997-2001, International Business Machines
|
1999-12-09 23:27:55 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File UMUTEX.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/02/97 aliu Creation.
|
|
|
|
* 04/07/99 srl rewrite - C interface, multiple mutices
|
|
|
|
* 05/13/99 stephen Changed to umutex (from cmutex)
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UMUTEX_H
|
|
|
|
#define UMUTEX_H
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-01-23 17:17:06 +00:00
|
|
|
/**
|
|
|
|
* Mutex data type.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
typedef void *UMTX;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-08-30 17:52:53 +00:00
|
|
|
/* APP_NO_THREADS is an old symbol. We'll honour it if present. */
|
|
|
|
#ifdef APP_NO_THREADS
|
|
|
|
# define ICU_USE_THREADS 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Default: use threads. */
|
|
|
|
#ifndef ICU_USE_THREADS
|
|
|
|
# define ICU_USE_THREADS 1
|
|
|
|
#endif
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
* Code within this library which accesses protected data should
|
|
|
|
* instantiate a Mutex object while doing so. Notice that there is
|
|
|
|
* only one coarse-grained lock which applies to this entire library,
|
|
|
|
* so keep locking short and sweet.
|
|
|
|
*
|
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* void Function(int arg1, int arg2)
|
|
|
|
* {
|
|
|
|
* static Object* foo; // Shared read-write object
|
|
|
|
* Mutex mutex;
|
|
|
|
* foo->Method();
|
|
|
|
* // When 'mutex' goes out of scope and gets destroyed here
|
|
|
|
* // the lock is released
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Note: Do NOT use the form 'Mutex mutex();' as that merely
|
|
|
|
* forward-declares a function returning a Mutex. This is a common
|
|
|
|
* mistake which silently slips through the compiler!! */
|
|
|
|
|
|
|
|
|
|
|
|
/* Lock a mutex. Pass in NULL if you want the (ick) Single Global
|
2002-07-03 12:05:56 +00:00
|
|
|
Mutex.
|
|
|
|
* @param mutex The given mutex to be locked
|
|
|
|
*/
|
2001-07-03 20:35:27 +00:00
|
|
|
U_CAPI void U_EXPORT2 umtx_lock ( UMTX* mutex );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Unlock a mutex. Pass in NULL if you want the single global
|
2002-07-03 12:05:56 +00:00
|
|
|
mutex.
|
|
|
|
* @param mutex The given mutex to be unlocked
|
|
|
|
*/
|
1999-10-18 23:44:20 +00:00
|
|
|
U_CAPI void U_EXPORT2 umtx_unlock ( UMTX* mutex );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Initialize a mutex. Use it this way:
|
2002-07-03 12:05:56 +00:00
|
|
|
umtx_init( &aMutex );
|
|
|
|
* @param mutex The given mutex to be initialized
|
|
|
|
*/
|
1999-10-18 23:44:20 +00:00
|
|
|
U_CAPI void U_EXPORT2 umtx_init ( UMTX* mutex );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-03 20:35:27 +00:00
|
|
|
/* Destroy a mutex. This will free the resources of a mutex.
|
|
|
|
Use it this way:
|
2002-07-03 12:05:56 +00:00
|
|
|
umtx_destroy( &aMutex );
|
|
|
|
* @param mutex The given mutex to be destroyed
|
|
|
|
*/
|
2001-07-03 20:35:27 +00:00
|
|
|
U_CAPI void U_EXPORT2 umtx_destroy( UMTX *mutex );
|
|
|
|
|
2002-04-23 23:24:25 +00:00
|
|
|
/* Is a mutex initialized? This function isn't normally needed
|
|
|
|
because umtx_lock will initialize the mutex for you.
|
|
|
|
Use it this way:
|
|
|
|
umtx_isInitialized( &aMutex ); */
|
|
|
|
U_CAPI UBool U_EXPORT2 umtx_isInitialized( UMTX *mutex );
|
|
|
|
|
2002-03-09 00:36:54 +00:00
|
|
|
/*
|
|
|
|
* Atomic Increment and Decrement of an int32_t value.
|
|
|
|
*
|
|
|
|
* Return Values:
|
|
|
|
* If the result of the operation is zero, the return zero.
|
|
|
|
* If the result of the operation is not zero, the sign of returned value
|
|
|
|
* is the same as the sign of the result, but the returned value itself may
|
|
|
|
* be different from the result of the operation.
|
|
|
|
*/
|
|
|
|
U_CAPI int32_t U_EXPORT2 umtx_atomic_inc(int32_t *);
|
|
|
|
U_CAPI int32_t U_EXPORT2 umtx_atomic_dec(int32_t *);
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif /*_CMUTEX*/
|
|
|
|
/*eof*/
|
|
|
|
|
|
|
|
|
|
|
|
|