ICU-10184 umutex.h, change to C++ only, in preparation for build time user mutex support.

X-SVN-Rev: 34029
This commit is contained in:
Andy Heninger 2013-08-09 19:53:07 +00:00
parent bea4641b0d
commit 0061d3a9b7
14 changed files with 72 additions and 57 deletions

View file

@ -0,0 +1,39 @@
/*
**********************************************************************
* Copyright (C) 2013, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
* File cmutex.h
*
* Minimal plain C declarations for ICU mutex functions.
* This header provides a transition path for plain C files that
* formerly included mutex.h, which is now a C++ only header.
*
* This header should not be used for new code.
*
* C++ files should include umutex.h, not this header.
*
*/
#ifndef __CMUTEX_H__
#define __CMUTEX_H__
typedef struct UMutex UMutex;
/* Lock a mutex.
* @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.
*/
U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex);
/* Unlock a mutex.
* @param mutex The given mutex to be unlocked. Pass NULL to specify
* the global ICU mutex.
*/
U_INTERNAL void U_EXPORT2 umtx_unlock (UMutex* mutex);
#endif

View file

@ -345,7 +345,9 @@
<ClCompile Include="udata.cpp" />
<ClCompile Include="udatamem.c" />
<ClCompile Include="udataswp.c" />
<ClCompile Include="uinit.c" />
<ClCompile Include="uinit.cpp">
<DisableLanguageExtensions>false</DisableLanguageExtensions>
</ClCompile>
<ClCompile Include="umapfile.c">
<DisableLanguageExtensions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</DisableLanguageExtensions>
<DisableLanguageExtensions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</DisableLanguageExtensions>

View file

@ -259,7 +259,7 @@
<ClCompile Include="udataswp.c">
<Filter>data &amp; memory</Filter>
</ClCompile>
<ClCompile Include="uinit.c">
<ClCompile Include="uinit.cpp">
<Filter>data &amp; memory</Filter>
</ClCompile>
<ClCompile Include="umapfile.c">
@ -1103,4 +1103,4 @@
<Filter>collections</Filter>
</CustomBuild>
</ItemGroup>
</Project>
</Project>

View file

@ -16,7 +16,7 @@
#include "unicode/uclean.h"
#include "utracimp.h"
#include "ucln_cmn.h"
#include "umutex.h"
#include "cmutex.h"
#include "ucln.h"
#include "cmemory.h"
#include "uassert.h"
@ -25,25 +25,9 @@
#define UCLN_TYPE_IS_COMMON
#include "ucln_imp.h"
static UBool gICUInitialized = FALSE;
static UMutex gICUInitMutex = U_MUTEX_INITIALIZER;
static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT];
static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
U_CFUNC UBool ucln_mutexedInit(initFunc *func, UErrorCode *status) {
UBool initialized = FALSE;
umtx_lock(&gICUInitMutex);
if (!gICUInitialized && U_SUCCESS(*status)) {
if (func != NULL) {
func(status);
}
gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
initialized = TRUE;
}
umtx_unlock(&gICUInitMutex);
return initialized;
}
/************************************************
The cleanup order is important in this function.
@ -59,7 +43,6 @@ u_cleanup(void)
ucln_lib_cleanup();
cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
gICUInitialized = FALSE;
UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
/*#if U_ENABLE_TRACING*/
utrace_cleanup();

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
* *
* Copyright (C) 2001-2012, International Business Machines *
* Copyright (C) 2001-2013, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
******************************************************************************
@ -50,6 +50,7 @@ typedef enum ECleanupCommonType {
UCLN_COMMON_UDATA,
UCLN_COMMON_PUTIL,
UCLN_COMMON_LIST_FORMATTER,
UCLN_COMMON_UINIT,
UCLN_COMMON_COUNT /* This must be last */
} ECleanupCommonType;

View file

@ -56,7 +56,7 @@
#include "ucnv_cnv.h"
#include "cmemory.h"
#include "cstring.h"
#include "umutex.h"
#include "cmutex.h"
/* control optimizations according to the platform */
#define MBCS_UNROLL_SINGLE_TO_BMP 1

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
* *
* Copyright (C) 2001-2012, International Business Machines *
* Copyright (C) 2001-2013, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
******************************************************************************
@ -19,13 +19,25 @@
#include "unicode/uclean.h"
#include "cmemory.h"
#include "icuplugimp.h"
#include "ucln.h"
#include "ucln_cmn.h"
#include "ucnv_io.h"
#include "umutex.h"
#include "utracimp.h"
static UInitOnce gICUInitOnce = U_INITONCE_INITIALIZER;
static UBool U_CALLCONV uinit_cleanup() {
gICUInitOnce.reset();
return TRUE;
}
static void U_CALLCONV
initData(UErrorCode *status)
initData(UErrorCode &status)
{
/* initialize plugins */
uplug_init(&status);
#if !UCONFIG_NO_CONVERSION
/*
* 2005-may-02
*
@ -38,9 +50,9 @@ initData(UErrorCode *status)
* for errors there, to make sure that the actual items they need are
* available.
*/
#if !UCONFIG_NO_CONVERSION
ucnv_io_countKnownConverters(status);
ucnv_io_countKnownConverters(&status);
#endif
ucln_common_registerCleanup(UCLN_COMMON_UINIT, uinit_cleanup);
}
/*
@ -49,10 +61,6 @@ initData(UErrorCode *status)
U_CAPI void U_EXPORT2
u_init(UErrorCode *status) {
UTRACE_ENTRY_OC(UTRACE_U_INIT);
/* initialize plugins */
uplug_init(status);
ucln_mutexedInit(initData, status);
umtx_initOnce(gICUInitOnce, &initData, *status);
UTRACE_EXIT_STATUS(*status);
}

View file

@ -85,7 +85,6 @@ inline int32_t umtx_atomic_dec(atomic_int32_t *var) {
typedef volatile LONG atomic_int32_t;
#define ATOMIC_INT32_T_INITIALIZER(val) val
#ifdef __cplusplus
inline int32_t umtx_loadAcquire(atomic_int32_t &var) {
return InterlockedCompareExchange(&var, 0, 0);
}
@ -102,8 +101,6 @@ inline int32_t umtx_atomic_inc(atomic_int32_t *var) {
inline int32_t umtx_atomic_dec(atomic_int32_t *var) {
return InterlockedDecrement(var);
}
#endif /* __cplusplus */
#elif U_HAVE_GCC_ATOMICS
@ -113,7 +110,6 @@ inline int32_t umtx_atomic_dec(atomic_int32_t *var) {
typedef int32_t atomic_int32_t;
#define ATOMIC_INT32_T_INITIALIZER(val) val
#ifdef __cplusplus
inline int32_t umtx_loadAcquire(atomic_int32_t &var) {
int32_t val = var;
__sync_synchronize();
@ -133,8 +129,6 @@ inline int32_t umtx_atomic_dec(atomic_int32_t *p) {
return __sync_sub_and_fetch(p, 1);
}
#endif /* __cplusplus */
#else
/*
@ -147,11 +141,9 @@ inline int32_t umtx_atomic_dec(atomic_int32_t *p) {
typedef int32_t atomic_int32_t;
#define ATOMIC_INT32_T_INITIALIZER(val) val
#ifdef __cplusplus
U_INTERNAL int32_t U_EXPORT2 umtx_loadAcquire(atomic_int32_t &var);
U_INTERNAL void U_EXPORT2 umtx_storeRelease(atomic_int32_t &var, int32_t val);
#endif /* __cplusplus */
U_INTERNAL int32_t U_EXPORT2 umtx_atomic_inc(atomic_int32_t *p);
@ -171,19 +163,14 @@ U_INTERNAL int32_t U_EXPORT2 umtx_atomic_dec(atomic_int32_t *p);
struct UInitOnce {
atomic_int32_t fState;
UErrorCode fErrCode;
#ifdef __cplusplus
void reset() {fState = 0; fState=0;};
UBool isReset() {return umtx_loadAcquire(fState) == 0;};
// Note: isReset() is used by service registration code.
// Thread safety of this usage needs review.
#endif
};
typedef struct UInitOnce UInitOnce;
#define U_INITONCE_INITIALIZER {ATOMIC_INT32_T_INITIALIZER(0), U_ZERO_ERROR}
#ifdef __cplusplus
// TODO: get all ICU files using umutex converted to C++,
// then remove the __cpluplus conditionals from this file.
U_CAPI UBool U_EXPORT2 umtx_initImplPreInit(UInitOnce &);
U_CAPI void U_EXPORT2 umtx_initImplPostInit(UInitOnce &, UBool success);
@ -261,7 +248,6 @@ template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T, UErrorCode &)
}
}
#endif /* __cplusplus */

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 1998-2010, International Business Machines
* Copyright (C) 1998-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -24,7 +24,7 @@
#include "unicode/ucnv.h"
#include "cstring.h"
#include "cmemory.h"
#include "umutex.h"
#include "cmutex.h"
#include "ustr_cnv.h"
/* mutexed access to a shared default converter ----------------------------- */

View file

@ -14,8 +14,8 @@
* created by: George Rhoten
*/
#ifndef __UCLN_CMN_H__
#define __UCLN_CMN_H__
#ifndef __UCLN_IN_H__
#define __UCLN_IN_H__
#include "unicode/utypes.h"
#include "ucln.h"

View file

@ -17,7 +17,6 @@
#include "cmemory.h"
#include "unicode/ustring.h"
#include "unicode/ulocdata.h"
#include "umutex.h"
#include "uresimp.h"
#include "ureslocs.h"

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
* *
* Copyright (C) 2001-2011, International Business Machines *
* Copyright (C) 2001-2013, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
******************************************************************************
@ -16,7 +16,6 @@
#include "ucln.h"
#include "ucln_io.h"
#include "umutex.h"
#include "uassert.h"
#ifndef U_IO_IMPLEMENTATION

View file

@ -22,7 +22,6 @@
#include "unicode/putil.h"
#include "cstring.h"
#include "cintltst.h"
#include "umutex.h"
#include "uassert.h"
#include "cmemory.h"
#include "unicode/uchar.h"

View file

@ -14,7 +14,6 @@
#include "unicode/uchar.h"
#include "unicode/ures.h"
#include "cintltst.h"
#include "umutex.h"
#include "unicode/utrace.h"
#include <stdlib.h>
#include <string.h>