]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/putilimp.h
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / common / putilimp.h
index cbec89bf590298b55238297be7d2cff8e23f9e53..e5473225b0b1db9a2e93cc977f1de35878a1fd53 100644 (file)
@@ -1,7 +1,9 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1997-2012, International Business Machines
+*   Copyright (C) 1997-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -65,7 +67,8 @@
  *
  * Do not use ptrdiff_t since it is signed. size_t is unsigned.
  */
-#if !defined(__intptr_t_defined) && !defined(UINTPTR_MAX)
+/* TODO: This check fails on some z environments. Filed a ticket #9357 for this. */
+#if !defined(__intptr_t_defined) && !defined(UINTPTR_MAX) && (U_PLATFORM != U_PF_OS390)
 typedef size_t uintptr_t;
 #endif
 
@@ -84,7 +87,7 @@ typedef size_t uintptr_t;
 
 #ifdef U_HAVE_NL_LANGINFO_CODESET
     /* Use the predefined value. */
-#elif U_PLATFORM_HAS_WIN32_API
+#elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_ANDROID || U_PLATFORM == U_PF_QNX
 #   define U_HAVE_NL_LANGINFO_CODESET 0
 #else
 #   define U_HAVE_NL_LANGINFO_CODESET 1
@@ -103,21 +106,37 @@ typedef size_t uintptr_t;
 #ifdef U_TZSET
     /* Use the predefined value. */
 #elif U_PLATFORM_USES_ONLY_WIN32_API
+    // UWP doesn't support tzset or environment variables for tz
+#if U_PLATFORM_HAS_WINUWP_API == 0
 #   define U_TZSET _tzset
+#endif
 #elif U_PLATFORM == U_PF_OS400
    /* not defined */
 #else
 #   define U_TZSET tzset
 #endif
 
-#ifdef U_TIMEZONE
+#if defined(U_TIMEZONE) || defined(U_HAVE_TIMEZONE)
     /* Use the predefined value. */
+#elif U_PLATFORM == U_PF_ANDROID
+#   define U_TIMEZONE timezone
 #elif U_PLATFORM_IS_LINUX_BASED
-#   define U_TIMEZONE __timezone
+#   if defined(__UCLIBC__)
+       /* uClibc does not have __timezone or _timezone. */
+#   elif defined(_NEWLIB_VERSION)
+#      define U_TIMEZONE      _timezone
+#   elif defined(__GLIBC__)
+       /* glibc */
+#      define U_TIMEZONE      __timezone
+#   endif
 #elif U_PLATFORM_USES_ONLY_WIN32_API
 #   define U_TIMEZONE _timezone
+#elif U_PLATFORM == U_PF_BSD && !defined(__NetBSD__)
+   /* not defined */
 #elif U_PLATFORM == U_PF_OS400
    /* not defined */
+#elif U_PLATFORM == U_PF_IPHONE
+   /* not defined */
 #else
 #   define U_TIMEZONE timezone
 #endif
@@ -125,7 +144,10 @@ typedef size_t uintptr_t;
 #ifdef U_TZNAME
     /* Use the predefined value. */
 #elif U_PLATFORM_USES_ONLY_WIN32_API
+    /* not usable on all windows platforms */
+#if U_PLATFORM_HAS_WINUWP_API == 0
 #   define U_TZNAME _tzname
+#endif
 #elif U_PLATFORM == U_PF_OS400
    /* not defined */
 #else
@@ -134,7 +156,7 @@ typedef size_t uintptr_t;
 
 #ifdef U_HAVE_MMAP
     /* Use the predefined value. */
-#elif U_PLATFORM_HAS_WIN32_API
+#elif U_PLATFORM_USES_ONLY_WIN32_API
 #   define U_HAVE_MMAP 0
 #else
 #   define U_HAVE_MMAP 1
@@ -157,7 +179,7 @@ typedef size_t uintptr_t;
  */
 #ifdef U_HAVE_DIRENT_H
     /* Use the predefined value. */
-#elif U_PLATFORM_HAS_WIN32_API
+#elif U_PLATFORM_USES_ONLY_WIN32_API
 #   define U_HAVE_DIRENT_H 0
 #else
 #   define U_HAVE_DIRENT_H 1
@@ -175,7 +197,13 @@ typedef size_t uintptr_t;
  */
 #ifdef U_HAVE_GCC_ATOMICS
     /* Use the predefined value. */
-#elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 401)
+#elif U_PLATFORM == U_PF_MINGW
+    #define U_HAVE_GCC_ATOMICS 0
+#elif U_GCC_MAJOR_MINOR >= 404 || defined(__clang__)
+    /* TODO: Intel icc and IBM xlc on AIX also support gcc atomics.  (Intel originated them.)
+     *       Add them for these compilers.
+     * Note: Clang sets __GNUC__ defines for version 4.2, so misses the 4.4 test here.
+     */
 #   define U_HAVE_GCC_ATOMICS 1
 #else
 #   define U_HAVE_GCC_ATOMICS 0
@@ -183,25 +211,47 @@ typedef size_t uintptr_t;
 
 /** @} */
 
-/*===========================================================================*/
-/** @{ Code alignment                                                        */
-/*===========================================================================*/
-
 /**
- * \def U_ALIGN_CODE
- * This is used to align code fragments to a specific byte boundary.
- * This is useful for getting consistent performance test results.
+ * \def U_HAVE_STD_ATOMICS
+ * Defines whether the standard C++11 <atomic> is available.
+ * ICU will use this when avialable,
+ * otherwise will fall back to compiler or platform specific alternatives.
  * @internal
  */
-#ifdef U_ALIGN_CODE
+#ifdef U_HAVE_STD_ATOMICS
     /* Use the predefined value. */
-#elif defined(_MSC_VER) && defined(_M_IX86) && !defined(_MANAGED)
-#   define U_ALIGN_CODE(boundarySize) __asm  align boundarySize
-#else
-#   define U_ALIGN_CODE(boundarySize) 
+#elif U_CPLUSPLUS_VERSION < 11
+    /* Not C++11, disable use of atomics */
+#   define U_HAVE_STD_ATOMICS 0
+#elif __clang__ && __clang_major__==3 && __clang_minor__<=1
+    /* Clang 3.1, has atomic variable initializer bug. */
+#   define U_HAVE_STD_ATOMICS 0
+#else 
+    /* U_HAVE_ATOMIC is typically set by an autoconf test of #include <atomic>  */
+    /*   Can be set manually, or left undefined, on platforms without autoconf. */
+#   if defined(U_HAVE_ATOMIC) &&  U_HAVE_ATOMIC 
+#      define U_HAVE_STD_ATOMICS 1
+#   else
+#      define U_HAVE_STD_ATOMICS 0
+#   endif
 #endif
 
-/** @} */
+
+/**
+ *  \def U_HAVE_CLANG_ATOMICS
+ *  Defines whether Clang c11 style built-in atomics are avaialable.
+ *  These are used in preference to gcc atomics when both are available.
+ */
+#ifdef U_HAVE_CLANG_ATOMICS
+    /* Use the predefined value. */
+#elif __has_builtin(__c11_atomic_load) && \
+    __has_builtin(__c11_atomic_store) && \
+    __has_builtin(__c11_atomic_fetch_add) && \
+    __has_builtin(__c11_atomic_fetch_sub)
+#    define U_HAVE_CLANG_ATOMICS 1
+#else
+#    define U_HAVE_CLANG_ATOMICS 0
+#endif
 
 /*===========================================================================*/
 /** @{ Programs used by ICU code                                             */
@@ -436,6 +486,12 @@ U_INTERNAL int32_t  U_EXPORT2 uprv_timezone(void);
  */
 U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n);
 
+/**
+ * Reset the global tzname cache.
+ * @internal
+ */
+U_INTERNAL void uprv_tzname_clear_cache();
+
 /**
  * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
  * This function is affected by 'faketime' and should be the bottleneck for all user-visible ICU time functions.