QtBase  v6.3.1
tst_bench_qthreadstorage.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <qtest.h>
30 #include <QtCore>
31 
33 
35 
36 class tst_QThreadStorage : public QObject
37 {
38  Q_OBJECT
39 
40 public:
42  virtual ~tst_QThreadStorage();
43 
44 public slots:
45  void init();
46  void cleanup();
47 
48 private slots:
49  void construct();
50  void get();
51  void set();
52 };
53 
55 {
56 }
57 
59 {
60 }
61 
63 {
64  dummy[1].setLocalData(new int(5));
65  dummy[2].setLocalData(new int(4));
66  dummy[3].setLocalData(new int(3));
67  tls1.setLocalData(new QString());
68 }
69 
71 {
72 }
73 
74 void tst_QThreadStorage::construct()
75 {
76  QBENCHMARK {
78  }
79 }
80 
81 
82 void tst_QThreadStorage::get()
83 {
85  ts.setLocalData(new int(45));
86 
87  int count = 0;
88  QBENCHMARK {
89  int *i = ts.localData();
90  count += *i;
91  }
92  ts.setLocalData(0);
93 }
94 
95 void tst_QThreadStorage::set()
96 {
98 
99  int count = 0;
100  QBENCHMARK {
101  ts.setLocalData(new int(count));
102  count++;
103  }
104  ts.setLocalData(0);
105 }
106 
108 
109 #include "tst_bench_qthreadstorage.moc"
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QThreadStorage class provides per-thread data storage.
void setLocalData(T t)
#define QString()
Definition: parse-defines.h:51
#define QBENCHMARK
Definition: qbenchmark.h:76
GLenum GLenum GLsizei count
#define QTEST_MAIN(TestObject)
Definition: qtest.h:664
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define slots
Definition: qtmetamacros.h:76
QThreadStorage< int * > dummy[8]
QThreadStorage< QString * > tls1