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
qtconcurrentiteratekernel.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qtconcurrentiteratekernel.h"
6
7
#
include
<
qdeadlinetimer
.
h
>
8
#
include
"private/qfunctions_p.h"
9
10
11
#
if
!
defined
(
QT_NO_CONCURRENT
)
||
defined
(
Q_QDOC
)
12
13
QT_BEGIN_NAMESPACE
14
15
enum
{
16
TargetRatio = 100
17
};
18
19
static
qint64
getticks
()
20
{
21
return
QDeadlineTimer::current(Qt::PreciseTimer).deadlineNSecs();
22
}
23
24
static
double
elapsed
(qint64 after, qint64 before)
25
{
26
return
double
(after - before);
27
}
28
29
namespace
QtConcurrent
{
30
31
/*!
32
\class QtConcurrent::Median
33
\inmodule QtConcurrent
34
\internal
35
*/
36
37
/*!
38
\class QtConcurrent::BlockSizeManager
39
\inmodule QtConcurrent
40
\internal
41
*/
42
43
/*!
44
\class QtConcurrent::ResultReporter
45
\inmodule QtConcurrent
46
\internal
47
*/
48
49
/*! \fn bool QtConcurrent::selectIteration(std::bidirectional_iterator_tag)
50
\internal
51
*/
52
53
/*! \fn bool QtConcurrent::selectIteration(std::forward_iterator_tag)
54
\internal
55
*/
56
57
/*! \fn bool QtConcurrent::selectIteration(std::random_access_iterator_tag)
58
\internal
59
*/
60
61
/*!
62
\class QtConcurrent::IterateKernel
63
\inmodule QtConcurrent
64
\internal
65
*/
66
67
/*! \internal
68
69
*/
70
BlockSizeManager
::
BlockSizeManager
(
QThreadPool
*
pool
,
int
iterationCount
)
71
:
maxBlockSize
(
iterationCount
/ (
std
::
max
(
pool
->
maxThreadCount
(), 1) * 2)),
72
beforeUser
(0),
afterUser
(0),
73
m_blockSize
(1)
74
{ }
75
76
// Records the time before user code.
77
void
BlockSizeManager
::
timeBeforeUser
()
78
{
79
if
(
blockSizeMaxed
())
80
return
;
81
82
beforeUser
=
getticks
();
83
controlPartElapsed
.
addValue
(
elapsed
(
beforeUser
,
afterUser
));
84
}
85
86
// Records the time after user code and adjust the block size if we are spending
87
// to much time in the for control code compared with the user code.
88
void
BlockSizeManager
::
timeAfterUser
()
89
{
90
if
(
blockSizeMaxed
())
91
return
;
92
93
afterUser
=
getticks
();
94
userPartElapsed
.
addValue
(
elapsed
(
afterUser
,
beforeUser
));
95
96
if
(
controlPartElapsed
.
isMedianValid
() ==
false
)
97
return
;
98
99
if
(
controlPartElapsed
.
median
() *
int
(
TargetRatio
) <
userPartElapsed
.
median
())
100
return
;
101
102
m_blockSize
=
qMin
(
m_blockSize
* 2,
maxBlockSize
);
103
104
#
ifdef
QTCONCURRENT_FOR_DEBUG
105
qDebug
() <<
QThread
::
currentThread
() <<
"adjusting block size"
<<
controlPartElapsed
.
median
() <<
userPartElapsed
.
median
() <<
m_blockSize
;
106
#
endif
107
108
// Reset the medians after adjusting the block size so we get
109
// new measurements with the new block size.
110
controlPartElapsed
.
reset
();
111
userPartElapsed
.
reset
();
112
}
113
114
int
BlockSizeManager
::
blockSize
()
115
{
116
return
m_blockSize
;
117
}
118
119
}
// namespace QtConcurrent
120
121
QT_END_NAMESPACE
122
123
#
endif
// QT_NO_CONCURRENT
QtConcurrent
\inmodule QtConcurrent
Definition
qtconcurrentiteratekernel.cpp:29
getticks
static qint64 getticks()
Definition
qtconcurrentiteratekernel.cpp:19
elapsed
static double elapsed(qint64 after, qint64 before)
Definition
qtconcurrentiteratekernel.cpp:24
qtbase
src
concurrent
qtconcurrentiteratekernel.cpp
Generated on
for Qt by
1.14.0