summaryrefslogtreecommitdiff
path: root/qmake/tools/qmutexpool.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qmutexpool.cpp') (more/less context) (show whitespace changes)
-rw-r--r--qmake/tools/qmutexpool.cpp78
1 files changed, 50 insertions, 28 deletions
diff --git a/qmake/tools/qmutexpool.cpp b/qmake/tools/qmutexpool.cpp
index 9ed2829..a8e7402 100644
--- a/qmake/tools/qmutexpool.cpp
+++ b/qmake/tools/qmutexpool.cpp
@@ -1 +1,36 @@
1/****************************************************************************
2** $Id$
3**
4** ...
5**
6** Copyright (C) 2002 Trolltech AS. All rights reserved.
7**
8** This file is part of the tools module of the Qt GUI Toolkit.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
20** licenses may use this file in accordance with the Qt Commercial License
21** Agreement provided with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
1#include "qmutexpool_p.h" 36#include "qmutexpool_p.h"
@@ -5,3 +40,2 @@
5#include <qthread.h> 40#include <qthread.h>
6#include <stdio.h>
7 41
@@ -9,17 +43,2 @@ QMutexPool *qt_global_mutexpool = 0;
9 43
10// this is an internal class used only for inititalizing the global mutexpool
11class QGlobalMutexPoolInitializer
12{
13public:
14 inline QGlobalMutexPoolInitializer()
15 {
16 /*
17 Purify will report a leak here. However, this mutex pool must be alive
18 until *everything* in Qt has been destructed. Unfortunately there is
19 no way to guarantee this, so we never destroy this mutex pool.
20 */
21 qt_global_mutexpool = new QMutexPool( TRUE );
22 }
23};
24QGlobalMutexPoolInitializer qt_global_mutexpool_initializer;
25 44
@@ -87,5 +106,8 @@ QGlobalMutexPoolInitializer qt_global_mutexpool_initializer;
87QMutexPool::QMutexPool( bool recursive, int size ) 106QMutexPool::QMutexPool( bool recursive, int size )
88 : mutex( FALSE ), mutexes( size ), recurs( recursive ) 107 : mutex( FALSE ), count( size ), recurs( recursive )
89{ 108{
90 mutexes.fill( 0 ); 109 mutexes = new QMutex*[count];
110 for ( int index = 0; index < count; ++index ) {
111 mutexes[index] = 0;
112 }
91} 113}
@@ -99,7 +121,8 @@ QMutexPool::~QMutexPool()
99 QMutexLocker locker( &mutex ); 121 QMutexLocker locker( &mutex );
100 QMutex **d = mutexes.data(); 122 for ( int index = 0; index < count; ++index ) {
101 for ( int index = 0; (uint) index < mutexes.size(); index++ ) { 123 delete mutexes[index];
102 delete d[index]; 124 mutexes[index] = 0;
103 d[index] = 0;
104 } 125 }
126 delete [] mutexes;
127 mutexes = 0;
105} 128}
@@ -112,6 +135,5 @@ QMutex *QMutexPool::get( void *address )
112{ 135{
113 QMutex **d = mutexes.data(); 136 int index = (int) ( (unsigned long) address % count );
114 int index = (int)( (ulong) address % mutexes.size() );
115 137
116 if ( ! d[index] ) { 138 if ( ! mutexes[index] ) {
117 // mutex not created, create one 139 // mutex not created, create one
@@ -121,4 +143,4 @@ QMutex *QMutexPool::get( void *address )
121 // 2 threads could be trying to create a mutex as the same index... 143 // 2 threads could be trying to create a mutex as the same index...
122 if ( ! d[index] ) { 144 if ( ! mutexes[index] ) {
123 d[index] = new QMutex( recurs ); 145 mutexes[index] = new QMutex( recurs );
124 } 146 }
@@ -126,3 +148,3 @@ QMutex *QMutexPool::get( void *address )
126 148
127 return d[index]; 149 return mutexes[index];
128} 150}