1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-12-09 23:27:55 +00:00
|
|
|
**********************************************************************
|
2015-04-09 23:16:55 +00:00
|
|
|
* Copyright (C) 1997-2015, 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"
|
2011-03-29 00:47:41 +00:00
|
|
|
#include "unicode/uclean.h"
|
2011-07-27 20:55:09 +00:00
|
|
|
#include "putilimp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2011-03-29 00:47:41 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
// Forward Declarations. UMutex is not in the ICU namespace (yet) because
|
|
|
|
// there are some remaining references from plain C.
|
2013-06-01 03:37:16 +00:00
|
|
|
struct UMutex;
|
2014-07-29 23:18:47 +00:00
|
|
|
struct UConditionVar;
|
2013-09-06 01:41:14 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
2013-06-01 03:37:16 +00:00
|
|
|
struct UInitOnce;
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
// Stringify macros, to allow #include of user supplied atomic & mutex files.
|
|
|
|
#define U_MUTEX_STR(s) #s
|
|
|
|
#define U_MUTEX_XSTR(s) U_MUTEX_STR(s)
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
2013-08-29 21:36:06 +00:00
|
|
|
* Low Level Atomic Operations.
|
2013-06-01 03:37:16 +00:00
|
|
|
* Compiler dependent. Not operating system dependent.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-08-30 01:23:42 +00:00
|
|
|
#if defined (U_USER_ATOMICS_H)
|
|
|
|
#include U_MUTEX_XSTR(U_USER_ATOMICS_H)
|
|
|
|
|
|
|
|
#elif U_HAVE_STD_ATOMICS
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
// C++11 atomics are available.
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
typedef std::atomic<int32_t> u_atomic_int32_t;
|
2013-06-01 03:37:16 +00:00
|
|
|
#define ATOMIC_INT32_T_INITIALIZER(val) ATOMIC_VAR_INIT(val)
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_loadAcquire(u_atomic_int32_t &var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return var.load(std::memory_order_acquire);
|
2013-08-29 21:36:06 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline void umtx_storeRelease(u_atomic_int32_t &var, int32_t val) {
|
2013-06-01 03:37:16 +00:00
|
|
|
var.store(val, std::memory_order_release);
|
2013-08-29 21:36:06 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_inc(u_atomic_int32_t *var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return var->fetch_add(1) + 1;
|
|
|
|
}
|
2013-08-29 21:36:06 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_dec(u_atomic_int32_t *var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return var->fetch_sub(1) - 1;
|
|
|
|
}
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
#elif U_PLATFORM_HAS_WIN32_API
|
|
|
|
|
|
|
|
// MSVC compiler. Reads and writes of volatile variables have
|
|
|
|
// acquire and release memory semantics, respectively.
|
|
|
|
// This is a Microsoft extension, not standard C++ behavior.
|
|
|
|
//
|
|
|
|
// Update: can't use this because of MinGW, built with gcc.
|
|
|
|
// Original plan was to use gcc atomics for MinGW, but they
|
|
|
|
// aren't supported, so we fold MinGW into this path.
|
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# define VC_EXTRALEAN
|
|
|
|
# define NOUSER
|
|
|
|
# define NOSERVICE
|
|
|
|
# define NOIME
|
|
|
|
# define NOMCX
|
2013-06-01 03:37:16 +00:00
|
|
|
# ifndef NOMINMAX
|
|
|
|
# define NOMINMAX
|
|
|
|
# endif
|
2012-10-05 21:22:02 +00:00
|
|
|
# include <windows.h>
|
2011-03-29 00:47:41 +00:00
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2013-08-30 01:23:42 +00:00
|
|
|
typedef volatile LONG u_atomic_int32_t;
|
2013-06-01 03:37:16 +00:00
|
|
|
#define ATOMIC_INT32_T_INITIALIZER(val) val
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_loadAcquire(u_atomic_int32_t &var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return InterlockedCompareExchange(&var, 0, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline void umtx_storeRelease(u_atomic_int32_t &var, int32_t val) {
|
2013-06-01 03:37:16 +00:00
|
|
|
InterlockedExchange(&var, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_inc(u_atomic_int32_t *var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return InterlockedIncrement(var);
|
|
|
|
}
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_dec(u_atomic_int32_t *var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return InterlockedDecrement(var);
|
|
|
|
}
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
|
2015-04-09 23:16:55 +00:00
|
|
|
#elif U_HAVE_CLANG_ATOMICS
|
|
|
|
/*
|
|
|
|
* Clang __c11 atomic built-ins
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
typedef _Atomic(int32_t) u_atomic_int32_t;
|
|
|
|
#define ATOMIC_INT32_T_INITIALIZER(val) val
|
|
|
|
|
|
|
|
inline int32_t umtx_loadAcquire(u_atomic_int32_t &var) {
|
|
|
|
return __c11_atomic_load(&var, __ATOMIC_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void umtx_storeRelease(u_atomic_int32_t &var, int32_t val) {
|
|
|
|
return __c11_atomic_store(&var, val, __ATOMIC_RELEASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int32_t umtx_atomic_inc(u_atomic_int32_t *var) {
|
|
|
|
return __c11_atomic_fetch_add(var, 1, __ATOMIC_SEQ_CST) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int32_t umtx_atomic_dec(u_atomic_int32_t *var) {
|
|
|
|
return __c11_atomic_fetch_sub(var, 1, __ATOMIC_SEQ_CST) - 1;
|
|
|
|
}
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
#elif U_HAVE_GCC_ATOMICS
|
2011-03-29 00:47:41 +00:00
|
|
|
/*
|
2013-06-01 03:37:16 +00:00
|
|
|
* gcc atomic ops. These are available on several other compilers as well.
|
2011-03-29 00:47:41 +00:00
|
|
|
*/
|
2013-09-06 01:41:14 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
2013-08-30 01:23:42 +00:00
|
|
|
typedef int32_t u_atomic_int32_t;
|
2013-06-01 03:37:16 +00:00
|
|
|
#define ATOMIC_INT32_T_INITIALIZER(val) val
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_loadAcquire(u_atomic_int32_t &var) {
|
2013-06-01 03:37:16 +00:00
|
|
|
int32_t val = var;
|
|
|
|
__sync_synchronize();
|
|
|
|
return val;
|
|
|
|
}
|
2011-03-29 00:47:41 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline void umtx_storeRelease(u_atomic_int32_t &var, int32_t val) {
|
2013-06-01 03:37:16 +00:00
|
|
|
__sync_synchronize();
|
|
|
|
var = val;
|
|
|
|
}
|
2011-03-29 00:47:41 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_inc(u_atomic_int32_t *p) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return __sync_add_and_fetch(p, 1);
|
|
|
|
}
|
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
inline int32_t umtx_atomic_dec(u_atomic_int32_t *p) {
|
2013-06-01 03:37:16 +00:00
|
|
|
return __sync_sub_and_fetch(p, 1);
|
|
|
|
}
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
#else
|
2005-03-25 23:24:47 +00:00
|
|
|
|
2011-03-29 00:47:41 +00:00
|
|
|
/*
|
2013-06-01 03:37:16 +00:00
|
|
|
* Unknown Platform. Use out-of-line functions, which in turn use mutexes.
|
|
|
|
* Slow but correct.
|
2011-03-29 00:47:41 +00:00
|
|
|
*/
|
2004-09-06 15:41:52 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
#define U_NO_PLATFORM_ATOMICS
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2013-08-30 01:23:42 +00:00
|
|
|
typedef int32_t u_atomic_int32_t;
|
2013-06-01 03:37:16 +00:00
|
|
|
#define ATOMIC_INT32_T_INITIALIZER(val) val
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_COMMON_API int32_t U_EXPORT2
|
|
|
|
umtx_loadAcquire(u_atomic_int32_t &var);
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_COMMON_API void U_EXPORT2
|
|
|
|
umtx_storeRelease(u_atomic_int32_t &var, int32_t val);
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_COMMON_API int32_t U_EXPORT2
|
|
|
|
umtx_atomic_inc(u_atomic_int32_t *p);
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_COMMON_API int32_t U_EXPORT2
|
|
|
|
umtx_atomic_dec(u_atomic_int32_t *p);
|
|
|
|
|
2013-09-06 04:14:48 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
#endif /* Low Level Atomic Ops Platfrom Chain */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
*
|
|
|
|
* UInitOnce Definitions.
|
|
|
|
* These are platform neutral.
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2013-06-01 03:37:16 +00:00
|
|
|
*************************************************************************************************/
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
struct UInitOnce {
|
2013-08-30 01:23:42 +00:00
|
|
|
u_atomic_int32_t fState;
|
2013-06-01 03:37:16 +00:00
|
|
|
UErrorCode fErrCode;
|
2013-08-30 01:23:42 +00:00
|
|
|
void reset() {fState = 0;};
|
2013-06-01 03:37:16 +00:00
|
|
|
UBool isReset() {return umtx_loadAcquire(fState) == 0;};
|
|
|
|
// Note: isReset() is used by service registration code.
|
|
|
|
// Thread safety of this usage needs review.
|
|
|
|
};
|
2013-08-09 19:53:07 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
#define U_INITONCE_INITIALIZER {ATOMIC_INT32_T_INITIALIZER(0), U_ZERO_ERROR}
|
|
|
|
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_COMMON_API UBool U_EXPORT2 umtx_initImplPreInit(UInitOnce &);
|
|
|
|
U_COMMON_API void U_EXPORT2 umtx_initImplPostInit(UInitOnce &);
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
template<class T> void umtx_initOnce(UInitOnce &uio, T *obj, void (T::*fp)()) {
|
|
|
|
if (umtx_loadAcquire(uio.fState) == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (umtx_initImplPreInit(uio)) {
|
|
|
|
(obj->*fp)();
|
2013-08-30 01:23:42 +00:00
|
|
|
umtx_initImplPostInit(uio);
|
2013-06-01 03:37:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// umtx_initOnce variant for plain functions, or static class functions.
|
|
|
|
// No context parameter.
|
|
|
|
inline void umtx_initOnce(UInitOnce &uio, void (*fp)()) {
|
|
|
|
if (umtx_loadAcquire(uio.fState) == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (umtx_initImplPreInit(uio)) {
|
|
|
|
(*fp)();
|
2013-08-30 01:23:42 +00:00
|
|
|
umtx_initImplPostInit(uio);
|
2013-06-01 03:37:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// umtx_initOnce variant for plain functions, or static class functions.
|
|
|
|
// With ErrorCode, No context parameter.
|
|
|
|
inline void umtx_initOnce(UInitOnce &uio, void (*fp)(UErrorCode &), UErrorCode &errCode) {
|
|
|
|
if (U_FAILURE(errCode)) {
|
|
|
|
return;
|
2013-08-29 21:36:06 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
if (umtx_loadAcquire(uio.fState) != 2 && umtx_initImplPreInit(uio)) {
|
|
|
|
// We run the initialization.
|
|
|
|
(*fp)(errCode);
|
|
|
|
uio.fErrCode = errCode;
|
2013-08-30 01:23:42 +00:00
|
|
|
umtx_initImplPostInit(uio);
|
2013-06-01 03:37:16 +00:00
|
|
|
} else {
|
|
|
|
// Someone else already ran the initialization.
|
|
|
|
if (U_FAILURE(uio.fErrCode)) {
|
|
|
|
errCode = uio.fErrCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// umtx_initOnce variant for plain functions, or static class functions,
|
|
|
|
// with a context parameter.
|
|
|
|
template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T), T context) {
|
|
|
|
if (umtx_loadAcquire(uio.fState) == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (umtx_initImplPreInit(uio)) {
|
|
|
|
(*fp)(context);
|
2013-08-30 01:23:42 +00:00
|
|
|
umtx_initImplPostInit(uio);
|
2013-06-01 03:37:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// umtx_initOnce variant for plain functions, or static class functions,
|
|
|
|
// with a context parameter and an error code.
|
|
|
|
template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T, UErrorCode &), T context, UErrorCode &errCode) {
|
|
|
|
if (U_FAILURE(errCode)) {
|
|
|
|
return;
|
2013-08-29 21:36:06 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
if (umtx_loadAcquire(uio.fState) != 2 && umtx_initImplPreInit(uio)) {
|
|
|
|
// We run the initialization.
|
|
|
|
(*fp)(context, errCode);
|
|
|
|
uio.fErrCode = errCode;
|
2013-08-30 01:23:42 +00:00
|
|
|
umtx_initImplPostInit(uio);
|
2013-06-01 03:37:16 +00:00
|
|
|
} else {
|
|
|
|
// Someone else already ran the initialization.
|
|
|
|
if (U_FAILURE(uio.fErrCode)) {
|
|
|
|
errCode = uio.fErrCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 01:41:14 +00:00
|
|
|
U_NAMESPACE_END
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2013-06-01 03:37:16 +00:00
|
|
|
* Mutex Definitions. Platform Dependent, #if platform chain follows.
|
|
|
|
* TODO: Add a C++11 version.
|
|
|
|
* Need to convert all mutex using files to C++ first.
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2013-06-01 03:37:16 +00:00
|
|
|
*************************************************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2013-08-30 01:23:42 +00:00
|
|
|
#if defined(U_USER_MUTEX_H)
|
|
|
|
// #inlcude "U_USER_MUTEX_H"
|
|
|
|
#include U_MUTEX_XSTR(U_USER_MUTEX_H)
|
|
|
|
|
|
|
|
#elif U_PLATFORM_HAS_WIN32_API
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
/* Windows Definitions.
|
|
|
|
* Windows comes first in the platform chain.
|
|
|
|
* Cygwin (and possibly others) have both WIN32 and POSIX APIs. Prefer Win32 in this case.
|
2012-10-05 21:22:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
/* For CRITICAL_SECTION */
|
2012-10-05 21:22:02 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
/*
|
2013-08-29 21:36:06 +00:00
|
|
|
* Note: there is an earlier include of windows.h in this file, but it is in
|
2013-06-01 03:37:16 +00:00
|
|
|
* different conditionals.
|
|
|
|
* This one is needed if we are using C++11 for atomic ops, but
|
|
|
|
* win32 APIs for Critical Sections.
|
2012-10-05 21:22:02 +00:00
|
|
|
*/
|
2013-08-29 21:36:06 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# define VC_EXTRALEAN
|
|
|
|
# define NOUSER
|
|
|
|
# define NOSERVICE
|
|
|
|
# define NOIME
|
|
|
|
# define NOMCX
|
|
|
|
# ifndef NOMINMAX
|
|
|
|
# define NOMINMAX
|
|
|
|
# endif
|
|
|
|
# include <windows.h>
|
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
|
|
|
|
typedef struct UMutex {
|
2013-10-18 20:05:25 +00:00
|
|
|
icu::UInitOnce fInitOnce;
|
2013-06-01 03:37:16 +00:00
|
|
|
CRITICAL_SECTION fCS;
|
2012-10-05 21:22:02 +00:00
|
|
|
} UMutex;
|
|
|
|
|
|
|
|
/* Initializer for a static UMUTEX. Deliberately contains no value for the
|
|
|
|
* CRITICAL_SECTION.
|
|
|
|
*/
|
2013-06-01 03:37:16 +00:00
|
|
|
#define U_MUTEX_INITIALIZER {U_INITONCE_INITIALIZER}
|
|
|
|
|
2014-07-29 23:18:47 +00:00
|
|
|
struct UConditionVar {
|
|
|
|
HANDLE fEntryGate;
|
|
|
|
HANDLE fExitGate;
|
|
|
|
int32_t fWaitCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define U_CONDITION_INITIALIZER {NULL, NULL, 0}
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
|
|
|
|
#elif U_PLATFORM_IMPLEMENTS_POSIX
|
2013-06-01 03:37:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* POSIX platform
|
|
|
|
*/
|
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
struct UMutex {
|
|
|
|
pthread_mutex_t fMutex;
|
|
|
|
};
|
2013-06-01 03:37:16 +00:00
|
|
|
typedef struct UMutex UMutex;
|
|
|
|
#define U_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER}
|
|
|
|
|
2014-07-29 23:18:47 +00:00
|
|
|
struct UConditionVar {
|
|
|
|
pthread_cond_t fCondition;
|
|
|
|
};
|
|
|
|
#define U_CONDITION_INITIALIZER {PTHREAD_COND_INITIALIZER}
|
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
#else
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-08-29 21:36:06 +00:00
|
|
|
/*
|
|
|
|
* Unknow platform type.
|
2013-06-01 03:37:16 +00:00
|
|
|
* This is an error condition. ICU requires mutexes.
|
|
|
|
*/
|
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
#error Unknown Platform.
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2013-08-29 21:36:06 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
/**************************************************************************************
|
|
|
|
*
|
|
|
|
* Mutex Implementation function declaratations.
|
|
|
|
* Declarations are platform neutral.
|
|
|
|
* Implementations, in umutex.cpp, are platform specific.
|
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
2011-03-29 00:47:41 +00:00
|
|
|
/* Lock a mutex.
|
2003-08-05 01:25:54 +00:00
|
|
|
* @param mutex The given mutex to be locked. Pass NULL to specify
|
|
|
|
* the global ICU mutex. Recursive locks are an error
|
|
|
|
* and may cause a deadlock on some platforms.
|
2002-07-03 12:05:56 +00:00
|
|
|
*/
|
2013-08-29 21:36:06 +00:00
|
|
|
U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2012-10-05 21:22:02 +00:00
|
|
|
/* Unlock a mutex.
|
2003-08-05 01:25:54 +00:00
|
|
|
* @param mutex The given mutex to be unlocked. Pass NULL to specify
|
|
|
|
* the global ICU mutex.
|
2002-07-03 12:05:56 +00:00
|
|
|
*/
|
2013-06-01 03:37:16 +00:00
|
|
|
U_INTERNAL void U_EXPORT2 umtx_unlock (UMutex* mutex);
|
2002-03-09 00:36:54 +00:00
|
|
|
|
2014-07-29 23:18:47 +00:00
|
|
|
/*
|
|
|
|
* Wait on a condition variable.
|
|
|
|
* The calling thread will unlock the mutex and wait on the condition variable.
|
|
|
|
* The mutex must be locked by the calling thread when invoking this function.
|
|
|
|
*
|
|
|
|
* @param cond the condition variable to wait on.
|
|
|
|
* @param mutex the associated mutex.
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2 umtx_condWait(UConditionVar *cond, UMutex *mutex);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Broadcast wakeup of all threads waiting on a Condition.
|
|
|
|
* The associated mutex must be locked by the calling thread when calling
|
|
|
|
* this function; this is a temporary ICU restriction.
|
|
|
|
*
|
|
|
|
* @param cond the condition variable.
|
|
|
|
*/
|
|
|
|
U_INTERNAL void U_EXPORT2 umtx_condBroadcast(UConditionVar *cond);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Signal a condition variable, waking up one waiting thread.
|
|
|
|
* CAUTION: Do not use. Place holder only. Not implemented for Windows.
|
|
|
|
*/
|
|
|
|
U_INTERNAL void U_EXPORT2 umtx_condSignal(UConditionVar *cond);
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
#endif /* UMUTEX_H */
|
1999-08-16 21:50:52 +00:00
|
|
|
/*eof*/
|