Force Harfbuzz-NG to use the Qt atomics when built inside Qt
authorThiago Macieira <thiago.macieira@intel.com>
Sun, 1 Feb 2015 16:31:55 +0000 (14:31 -0200)
committerThiago Macieira <thiago.macieira@intel.com>
Tue, 10 Feb 2015 03:21:08 +0000 (03:21 +0000)
For most cases, the GCC/Intel atomics (__sync functions) are fine, but
there are some systems for which libgcc is incorrectly built (QNX
6.5.0). Additionally, this will allow Harfbuzz-NG to be supported in
exactly the same systems as Qt itself.

Task-number: QTBUG-43850
Change-Id: Ib53f57f70d4ad46863c45e74d60b0eb45ba9bd02
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro
src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh

index 6b51d9679ade99867e5396a1ee00c0d27b2edc8a..a8885d71df0924730e9a095ec19ae5e75abd38b9 100644 (file)
@@ -7,14 +7,14 @@ CONFIG += \
 
 load(qt_helper_lib)
 
-DEFINES += HAVE_OT HB_NO_UNICODE_FUNCS HB_DISABLE_DEPRECATED
+DEFINES += HAVE_OT HAVE_QT5_ATOMICS HB_NO_UNICODE_FUNCS HB_DISABLE_DEPRECATED
 
 # platform/compiler specific definitions
 DEFINES += HAVE_ATEXIT
-gcc: DEFINES += HAVE_INTEL_ATOMIC_PRIMITIVES
 unix: DEFINES += HAVE_PTHREAD HAVE_SCHED_H HAVE_SCHED_YIELD
 
 INCLUDEPATH += $$PWD/include
+INCLUDEPATH += $$OUT_PWD/../../../include
 
 SOURCES += \
     $$PWD/src/hb-blob.cc \
index 60cbcf91be1f839ce13327f9694ad5e72d87b6ef..f15ef09799eff38819f90bbdcea3723efef1525d 100644 (file)
 
 #if 0
 
+#elif !defined(HB_NO_MT) && defined(HAVE_QT5_ATOMICS)
+#include <QtCore/qatomic.h>
+
+QT_USE_NAMESPACE
+
+namespace {
+// We need to cast hb_atomic_int_t to QAtomicInt and pointers to
+// QAtomicPointer instead of using QAtomicOps, otherwise we get a failed
+// overload resolution of the template arguments for testAndSetOrdered.
+template <typename T> QAtomicPointer<T> *makeAtomicPointer(T * const &ptr)
+{
+    return reinterpret_cast<QAtomicPointer<T> *>(const_cast<T **>(&ptr));
+}
+}
+
+typedef int                                         hb_atomic_int_t;
+#define hb_atomic_int_add(AI, V)                    reinterpret_cast<QAtomicInt &>(AI).fetchAndAddOrdered(V)
+#define hb_atomic_ptr_get(P)                        makeAtomicPointer(*P)->loadAcquire()
+#define hb_atomic_ptr_cmpexch(P,O,N)                makeAtomicPointer(*P)->testAndSetOrdered((O), (N))
 
 #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__))