author | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
commit | 155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (unidiff) | |
tree | e6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/tools/qmutexpool.cpp | |
parent | 86703e8a5527ef114facd02c005b6b3a7e62e263 (diff) | |
download | opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2 |
update qmake to 1.05a
-rw-r--r-- | qmake/tools/qmutexpool.cpp | 78 |
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,27 +1,46 @@ | |||
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" |
2 | 37 | ||
3 | #ifdef QT_THREAD_SUPPORT | 38 | #ifdef QT_THREAD_SUPPORT |
4 | 39 | ||
5 | #include <qthread.h> | 40 | #include <qthread.h> |
6 | #include <stdio.h> | ||
7 | 41 | ||
8 | QMutexPool *qt_global_mutexpool = 0; | 42 | QMutexPool *qt_global_mutexpool = 0; |
9 | 43 | ||
10 | // this is an internal class used only for inititalizing the global mutexpool | ||
11 | class QGlobalMutexPoolInitializer | ||
12 | { | ||
13 | public: | ||
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 | }; | ||
24 | QGlobalMutexPoolInitializer qt_global_mutexpool_initializer; | ||
25 | 44 | ||
26 | /*! | 45 | /*! |
27 | \class QMutexPool qmutexpool_p.h | 46 | \class QMutexPool qmutexpool_p.h |
@@ -85,9 +104,12 @@ QGlobalMutexPoolInitializer qt_global_mutexpool_initializer; | |||
85 | QMutexPool is destructed. | 104 | QMutexPool is destructed. |
86 | */ | 105 | */ |
87 | QMutexPool::QMutexPool( bool recursive, int size ) | 106 | QMutexPool::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 | } |
92 | 114 | ||
93 | /*! | 115 | /*! |
@@ -97,11 +119,12 @@ QMutexPool::QMutexPool( bool recursive, int size ) | |||
97 | QMutexPool::~QMutexPool() | 119 | QMutexPool::~QMutexPool() |
98 | { | 120 | { |
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 | } |
106 | 129 | ||
107 | /*! | 130 | /*! |
@@ -110,21 +133,20 @@ QMutexPool::~QMutexPool() | |||
110 | */ | 133 | */ |
111 | QMutex *QMutexPool::get( void *address ) | 134 | 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 |
118 | 140 | ||
119 | QMutexLocker locker( &mutex ); | 141 | QMutexLocker locker( &mutex ); |
120 | // we need to check once again that the mutex hasn't been created, since | 142 | // we need to check once again that the mutex hasn't been created, since |
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 | } |
125 | } | 147 | } |
126 | 148 | ||
127 | return d[index]; | 149 | return mutexes[index]; |
128 | } | 150 | } |
129 | 151 | ||
130 | #endif | 152 | #endif |