qmutexpool.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/thread/qmutexpool.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qatomic.h"-
41#include "qmutexpool_p.h"-
42-
43#ifndef QT_NO_THREAD-
44-
45QT_BEGIN_NAMESPACE-
46-
47Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
executed 16 times by 16 tests: end of block
Executed by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
executed 16 times by 16 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
executed 143976 times by 32 tests: return &holder.value;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • ...
guard.load() =...c::InitializedDescription
TRUEevaluated 16 times by 16 tests
Evaluated by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
FALSEnever evaluated
0-143976
48-
49/*!-
50 \class QMutexPool-
51 \inmodule QtCore-
52 \brief The QMutexPool class provides a pool of QMutex objects.-
53-
54 \internal-
55-
56 \ingroup thread-
57-
58 QMutexPool is a convenience class that provides access to a fixed-
59 number of QMutex objects.-
60-
61 Typical use of a QMutexPool is in situations where it is not-
62 possible or feasible to use one QMutex for every protected object.-
63 The mutex pool will return a mutex based on the address of the-
64 object that needs protection.-
65-
66 For example, consider this simple class:-
67-
68 \snippet code/src_corelib_thread_qmutexpool.cpp 0-
69-
70 Adding a QMutex member to the Number class does not make sense,-
71 because it is so small. However, in order to ensure that access to-
72 each Number is protected, you need to use a mutex. In this case, a-
73 QMutexPool would be ideal.-
74-
75 Code to calculate the square of a number would then look something-
76 like this:-
77-
78 \snippet code/src_corelib_thread_qmutexpool.cpp 1-
79-
80 This function will safely calculate the square of a number, since-
81 it uses a mutex from a QMutexPool. The mutex is locked and-
82 unlocked automatically by the QMutexLocker class. See the-
83 QMutexLocker documentation for more details.-
84*/-
85-
86/*!-
87 Constructs a QMutexPool, reserving space for \a size QMutexes. All-
88 mutexes in the pool are created with \a recursionMode. By default,-
89 all mutexes are non-recursive.-
90-
91 The QMutexes are created when needed, and deleted when the-
92 QMutexPool is destructed.-
93*/-
94QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)-
95 : mutexes(size), recursionMode(recursionMode)-
96{-
97 for (int index = 0; index < mutexes.count(); ++index) {
index < mutexes.count()Description
TRUEevaluated 2096 times by 16 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 16 times by 16 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
16-2096
98 mutexes[index].store(0);-
99 }
executed 2096 times by 16 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
2096
100}
executed 16 times by 16 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
16
101-
102/*!-
103 Destructs a QMutexPool. All QMutexes that were created by the pool-
104 are deleted.-
105*/-
106QMutexPool::~QMutexPool()-
107{-
108 for (int index = 0; index < mutexes.count(); ++index)
index < mutexes.count()Description
TRUEevaluated 2096 times by 16 tests
Evaluated by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
FALSEevaluated 16 times by 16 tests
Evaluated by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
16-2096
109 delete mutexes[index].load();
executed 2096 times by 16 tests: delete mutexes[index].load();
Executed by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
2096
110}
executed 16 times by 16 tests: end of block
Executed by:
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslkey - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlinputsource - unknown status
  • tst_spdy - unknown status
16
111-
112/*!-
113 Returns the global QMutexPool instance.-
114*/-
115QMutexPool *QMutexPool::instance()-
116{-
117 return globalMutexPool();
never executed: return globalMutexPool();
0
118}-
119-
120/*!-
121 \fn QMutexPool::get(const void *address)-
122 Returns a QMutex from the pool. QMutexPool uses the value \a address-
123 to determine which mutex is returned from the pool.-
124*/-
125-
126/*!-
127 \internal-
128 create the mutex for the given index-
129 */-
130QMutex *QMutexPool::createMutex(int index)-
131{-
132 // mutex not created, create one-
133 QMutex *newMutex = new QMutex(recursionMode);-
134 if (!mutexes[index].testAndSetRelease(0, newMutex))
!mutexes[index...e(0, newMutex)Description
TRUEnever evaluated
FALSEevaluated 340 times by 17 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
0-340
135 delete newMutex;
never executed: delete newMutex;
0
136 return mutexes[index].load();
executed 340 times by 17 tests: return mutexes[index].load();
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
340
137}-
138-
139/*!-
140 Returns a QMutex from the global mutex pool.-
141*/-
142QMutex *QMutexPool::globalInstanceGet(const void *address)-
143{-
144 QMutexPool * const globalInstance = globalMutexPool();-
145 if (globalInstance == 0)
globalInstance == 0Description
TRUEnever evaluated
FALSEevaluated 143976 times by 32 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • ...
0-143976
146 return 0;
never executed: return 0;
0
147 return globalInstance->get(address);
executed 143976 times by 32 tests: return globalInstance->get(address);
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslCertificate
  • tst_QSslEllipticCurve
  • tst_QSslError
  • tst_QSslKey
  • tst_QSslSocket
  • tst_QSslSocket_onDemandCertificates_member
  • tst_QSslSocket_onDemandCertificates_static
  • tst_QTcpSocket
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhttpnetworkconnection - unknown status
  • tst_qnetworkaccessmanager_and_qprogressdialog - unknown status
  • tst_qnetworkdiskcache - unknown status
  • tst_qnetworkproxyfactory - unknown status
  • tst_qsslcertificate - unknown status
  • tst_qsslellipticcurve - unknown status
  • ...
143976
148}-
149-
150QT_END_NAMESPACE-
151-
152#endif // QT_NO_THREAD-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9