FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qatomic_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "core.h"
19 
20 #include <QtCore/QAtomicPointer>
21 class QAtomicInt;
22 
23 namespace qtcore {
24 
26 {
27 public:
28  // QAtomicInt
29  static int loadRelaxed(const QAtomicInt& atomInt);
30 
31  static void storeRelaxed(QAtomicInt* atomInt, int newVal);
32  static void storeRelease(QAtomicInt* atomInt, int newVal);
33 
34  // QAtomicPointer
35  template<typename T> static T* loadRelaxed(const QAtomicPointer<T>& atomPtr);
36 
37  template<typename T> static void storeRelaxed(QAtomicPointer<T>* atomPtr, T* newPtr);
38  template<typename T> static void storeRelease(QAtomicPointer<T>* atomPtr, T* newPtr);
39 };
40 
41 
42 
43 // --
44 // -- Implementation
45 // --
46 
47 template<typename T> T* QAtomicUtils::loadRelaxed(const QAtomicPointer<T>& atomPtr)
48 {
49 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
50  return atomPtr.load();
51 #else
52  return atomPtr;
53 #endif
54 }
55 
56 template<typename T> void QAtomicUtils::storeRelaxed(QAtomicPointer<T>* atomPtr, T* newPtr)
57 {
58 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
59  atomPtr->store(newPtr);
60 #else
61  atomPtr->fetchAndStoreRelaxed(newPtr);
62 #endif
63 }
64 
65 template<typename T> void QAtomicUtils::storeRelease(QAtomicPointer<T>* atomPtr, T* newPtr)
66 {
67 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
68  atomPtr->storeRelease(newPtr);
69 #else
70  atomPtr->fetchAndStoreRelease(newPtr);
71 #endif
72 }
73 
74 } // namespace qtcore
Provides a collection of tools around QAtomicInt and QAtomicPointer.
Definition: qatomic_utils.h:25
static void storeRelease(QAtomicInt *atomInt, int newVal)
Definition: qatomic_utils.cpp:54
static int loadRelaxed(const QAtomicInt &atomInt)
Definition: qatomic_utils.cpp:36
#define QTTOOLS_CORE_EXPORT
Definition: core.h:27
Definition: grid_numbering.cpp:19
static void storeRelaxed(QAtomicInt *atomInt, int newVal)
Definition: qatomic_utils.cpp:45