]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/umutex.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / common / umutex.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (C) 1997-2001, International Business Machines
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6*
7* File UMUTEX.H
8*
9* Modification History:
10*
11* Date Name Description
12* 04/02/97 aliu Creation.
13* 04/07/99 srl rewrite - C interface, multiple mutices
14* 05/13/99 stephen Changed to umutex (from cmutex)
15******************************************************************************
16*/
17
18#ifndef UMUTEX_H
19#define UMUTEX_H
20
21#include "unicode/utypes.h"
22
23/**
24 * Mutex data type.
25 * @internal
26 */
27typedef void *UMTX;
28
29/* APP_NO_THREADS is an old symbol. We'll honour it if present. */
30#ifdef APP_NO_THREADS
31# define ICU_USE_THREADS 0
32#endif
33
34/* Default: use threads. */
35#ifndef ICU_USE_THREADS
36# define ICU_USE_THREADS 1
37#endif
38
39/*
40 * Code within this library which accesses protected data should
41 * instantiate a Mutex object while doing so. Notice that there is
42 * only one coarse-grained lock which applies to this entire library,
43 * so keep locking short and sweet.
44 *
45 * For example:
46 *
47 * void Function(int arg1, int arg2)
48 * {
49 * static Object* foo; // Shared read-write object
50 * Mutex mutex;
51 * foo->Method();
52 * // When 'mutex' goes out of scope and gets destroyed here
53 * // the lock is released
54 * }
55 *
56 * Note: Do NOT use the form 'Mutex mutex();' as that merely
57 * forward-declares a function returning a Mutex. This is a common
58 * mistake which silently slips through the compiler!! */
59
60
61/* Lock a mutex. Pass in NULL if you want the (ick) Single Global
62 Mutex.
63 * @param mutex The given mutex to be locked
64 */
65U_CAPI void U_EXPORT2 umtx_lock ( UMTX* mutex );
66
67/* Unlock a mutex. Pass in NULL if you want the single global
68 mutex.
69 * @param mutex The given mutex to be unlocked
70 */
71U_CAPI void U_EXPORT2 umtx_unlock ( UMTX* mutex );
72
73/* Initialize a mutex. Use it this way:
74 umtx_init( &aMutex );
75 * ICU Mutexes, aside from the global mutex, must be explicitly initialized
76 * before use.
77 * @param mutex The given mutex to be initialized
78 */
79U_CAPI void U_EXPORT2 umtx_init ( UMTX* mutex );
80
81/* Destroy a mutex. This will free the resources of a mutex.
82 Use it this way:
83 umtx_destroy( &aMutex );
84 * @param mutex The given mutex to be destroyed
85 */
86U_CAPI void U_EXPORT2 umtx_destroy( UMTX *mutex );
87
88/* Is a mutex initialized?
89 Use it this way:
90 umtx_isInitialized( &aMutex );
91 This function is not normally needed. It is more efficient to
92 unconditionally call umtx_init(&aMutex) than it is to check first.
93 * @param mutex The given mutex to be tested
94*/
95U_CAPI UBool U_EXPORT2 umtx_isInitialized( UMTX *mutex );
96
97/*
98 * Atomic Increment and Decrement of an int32_t value.
99 *
100 * Return Values:
101 * If the result of the operation is zero, the return zero.
102 * If the result of the operation is not zero, the sign of returned value
103 * is the same as the sign of the result, but the returned value itself may
104 * be different from the result of the operation.
105 */
106U_CAPI int32_t U_EXPORT2 umtx_atomic_inc(int32_t *);
107U_CAPI int32_t U_EXPORT2 umtx_atomic_dec(int32_t *);
108
109
110#endif /*_CMUTEX*/
111/*eof*/
112
113
114