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
6
struct
Data
7
{
8
QAtomicInt
atomicInt
;
9
};
10
11
struct
MySharedType
12
{
13
Data
*
data
;
14
Data
*
d
;
15
MySharedType
&
operator
=(
const
MySharedType
&other);
16
};
17
18
//! [0]
19
MySharedType
&
MySharedType
::
operator
=(
const
MySharedType
&other)
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
31
bool
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
54
int
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
73
template
<
typename
T>
74
75
T *
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
}
wrapInTFunction
T * wrapInTFunction(T *currentValue, T *newValue, T valueToAdd)
Definition
src_corelib_thread_qatomic.cpp:75
wrapInFunction
int wrapInFunction(int currentValue, int newValue, int valueToAdd)
Definition
src_corelib_thread_qatomic.cpp:54
examples
bool examples(int currentValue, int expectedValue, int newValue)
[0]
Definition
src_corelib_thread_qatomic.cpp:31
Data
Definition
src_corelib_thread_qatomic.cpp:7
Data::atomicInt
QAtomicInt atomicInt
Definition
src_corelib_thread_qatomic.cpp:8
MySharedType
Definition
src_corelib_thread_qatomic.cpp:12
MySharedType::operator=
MySharedType & operator=(const MySharedType &other)
[0]
Definition
src_corelib_thread_qatomic.cpp:19
MySharedType::d
Data * d
Definition
src_corelib_thread_qatomic.cpp:14
MySharedType::data
Data * data
Definition
src_corelib_thread_qatomic.cpp:13
qtbase
src
corelib
doc
snippets
code
src_corelib_thread_qatomic.cpp
Generated on
for Qt by
1.14.0