From b525ec2eb0bb441ac0dcd0a055efcad08fe6957c Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 17 Aug 2017 09:31:19 +0300 Subject: Android: Fix compile with unified headers Unified headers now defines _POSIX_THREAD_SAFE_FUNCTIONS but not all libc functions are available in all Android API versions. Change-Id: I01c94f0b89e7f8aa8575e7bbda28d9fe41a68ff1 Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.cpp | 74 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 12e908f09f..a9664e7564 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3344,7 +3344,11 @@ bool qunsetenv(const char *varName) #endif } -#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) +#if defined(Q_OS_ANDROID) && (__ANDROID_API__ < 21) +typedef QThreadStorage AndroidRandomStorage; +Q_GLOBAL_STATIC(AndroidRandomStorage, randomTLS) + +#elif defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) # if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500) // older versions of INTEGRITY used a long instead of a uint for the seed. @@ -3355,10 +3359,6 @@ typedef uint SeedStorageType; typedef QThreadStorage SeedStorage; Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value - -#elif defined(Q_OS_ANDROID) -typedef QThreadStorage AndroidRandomStorage; -Q_GLOBAL_STATIC(AndroidRandomStorage, randomTLS) #endif /*! @@ -3378,21 +3378,7 @@ Q_GLOBAL_STATIC(AndroidRandomStorage, randomTLS) */ void qsrand(uint seed) { -#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) - SeedStorage *seedStorage = randTLS(); - if (seedStorage) { - SeedStorageType *pseed = seedStorage->localData(); - if (!pseed) - seedStorage->setLocalData(pseed = new SeedStorageType); - *pseed = seed; - } else { - //global static seed storage should always exist, - //except after being deleted by QGlobalStaticDeleter. - //But since it still can be called from destructor of another - //global static object, fallback to srand(seed) - srand(seed); - } -#elif defined(Q_OS_ANDROID) +#if defined(Q_OS_ANDROID) && (__ANDROID_API__ < 21) if (randomTLS->hasLocalData()) { randomTLS->localData().callMethod("setSeed", "(J)V", jlong(seed)); return; @@ -3407,6 +3393,20 @@ void qsrand(uint seed) } randomTLS->setLocalData(random); +#elif defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) + SeedStorage *seedStorage = randTLS(); + if (seedStorage) { + SeedStorageType *pseed = seedStorage->localData(); + if (!pseed) + seedStorage->setLocalData(pseed = new SeedStorageType); + *pseed = seed; + } else { + //global static seed storage should always exist, + //except after being deleted by QGlobalStaticDeleter. + //But since it still can be called from destructor of another + //global static object, fallback to srand(seed) + srand(seed); + } #else // On Windows srand() and rand() already use Thread-Local-Storage // to store the seed between calls @@ -3432,23 +3432,7 @@ void qsrand(uint seed) */ int qrand() { -#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) - SeedStorage *seedStorage = randTLS(); - if (seedStorage) { - SeedStorageType *pseed = seedStorage->localData(); - if (!pseed) { - seedStorage->setLocalData(pseed = new SeedStorageType); - *pseed = 1; - } - return rand_r(pseed); - } else { - //global static seed storage should always exist, - //except after being deleted by QGlobalStaticDeleter. - //But since it still can be called from destructor of another - //global static object, fallback to rand() - return rand(); - } -#elif defined(Q_OS_ANDROID) +#if defined(Q_OS_ANDROID) && (__ANDROID_API__ < 21) AndroidRandomStorage *randomStorage = randomTLS(); if (!randomStorage) return rand(); @@ -3468,6 +3452,22 @@ int qrand() randomStorage->setLocalData(random); return random.callMethod("nextInt", "(I)I", RAND_MAX); +#elif defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) + SeedStorage *seedStorage = randTLS(); + if (seedStorage) { + SeedStorageType *pseed = seedStorage->localData(); + if (!pseed) { + seedStorage->setLocalData(pseed = new SeedStorageType); + *pseed = 1; + } + return rand_r(pseed); + } else { + //global static seed storage should always exist, + //except after being deleted by QGlobalStaticDeleter. + //But since it still can be called from destructor of another + //global static object, fallback to rand() + return rand(); + } #else // On Windows srand() and rand() already use Thread-Local-Storage // to store the seed between calls -- cgit v1.2.3