Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_thread_qatomic.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QAtomicInt>
5
6struct Data
7{
9};
10
17
18//! [0]
20{
21 (void) other.data->atomicInt.ref();
22 if (!data->atomicInt.deref()) {
23 // The last reference has been released
24 delete d;
25 }
26 d = other.d;
27 return *this;
28}
29//! [0]
30
31bool examples(int currentValue, int expectedValue, int newValue)
32{
33 {
34 //! [1]
35 if (currentValue == expectedValue) {
36 currentValue = newValue;
37 return true;
38 }
39 return false;
40 //! [1]
41 }
42
43 {
44 //! [4]
45 if (currentValue == expectedValue) {
46 currentValue = newValue;
47 return true;
48 }
49 return false;
50 //! [4]
51 }
52}
53
54int wrapInFunction(int currentValue, int newValue, int valueToAdd)
55{
56 {
57 //! [2]
58 int originalValue = currentValue;
59 currentValue = newValue;
60 return originalValue;
61 //! [2]
62 }
63
64 {
65 //! [3]
66 int originalValue = currentValue;
67 currentValue += valueToAdd;
68 return originalValue;
69 //! [3]
70 }
71}
72
73template <typename T>
74
75T *wrapInTFunction(T *currentValue, T *newValue, T valueToAdd)
76{
77 {
78 //! [5]
79 T *originalValue = currentValue;
80 currentValue = newValue;
81 return originalValue;
82 //! [5]
83 }
84
85 {
86 //! [6]
87 T *originalValue = currentValue;
88 currentValue += valueToAdd;
89 return originalValue;
90 //! [6]
91 }
92}
T * wrapInTFunction(T *currentValue, T *newValue, T valueToAdd)
int wrapInFunction(int currentValue, int newValue, int valueToAdd)
bool examples(int currentValue, int expectedValue, int newValue)
[0]
MySharedType & operator=(const MySharedType &other)
[0]