Changeset 43392 in webkit for trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp
- Timestamp:
- May 7, 2009, 11:47:19 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp
r43366 r43392 42 42 namespace WTF { 43 43 44 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const45 {46 return m_platformId == another.m_platformId;47 }48 49 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const50 {51 return m_platformId != another.m_platformId;52 }53 54 44 class ThreadPrivate : public QThread { 55 45 public: … … 80 70 static ThreadIdentifier mainThreadIdentifier; 81 71 72 static Mutex& threadMapMutex() 73 { 74 static Mutex mutex; 75 return mutex; 76 } 77 78 static HashMap<ThreadIdentifier, QThread*>& threadMap() 79 { 80 static HashMap<ThreadIdentifier, QThread*> map; 81 return map; 82 } 83 84 static ThreadIdentifier identifierByQthreadHandle(QThread*& thread) 85 { 86 MutexLocker locker(threadMapMutex()); 87 88 HashMap<ThreadIdentifier, QThread*>::iterator i = threadMap().begin(); 89 for (; i != threadMap().end(); ++i) { 90 if (i->second == thread) 91 return i->first; 92 } 93 94 return 0; 95 } 96 97 static ThreadIdentifier establishIdentifierForThread(QThread*& thread) 98 { 99 ASSERT(!identifierByQthreadHandle(thread)); 100 101 MutexLocker locker(threadMapMutex()); 102 103 static ThreadIdentifier identifierCount = 1; 104 105 threadMap().add(identifierCount, thread); 106 107 return identifierCount++; 108 } 109 110 static void clearThreadForIdentifier(ThreadIdentifier id) 111 { 112 MutexLocker locker(threadMapMutex()); 113 114 ASSERT(threadMap().contains(id)); 115 116 threadMap().remove(id); 117 } 118 119 static QThread* threadForIdentifier(ThreadIdentifier id) 120 { 121 MutexLocker locker(threadMapMutex()); 122 123 return threadMap().get(id); 124 } 125 82 126 void initializeThreading() 83 127 { 84 128 if (!atomicallyInitializedStaticMutex) { 85 129 atomicallyInitializedStaticMutex = new Mutex; 130 threadMapMutex(); 86 131 initializeRandomNumberGenerator(); 87 mainThreadIdentifier = ThreadIdentifier(QCoreApplication::instance()->thread()); 132 QThread* mainThread = QCoreApplication::instance()->thread(); 133 mainThreadIdentifier = identifierByQthreadHandle(mainThread); 134 if (!mainThreadIdentifier) 135 mainThreadIdentifier = establishIdentifierForThread(mainThread); 88 136 initializeMainThread(); 89 137 } … … 106 154 if (!thread) { 107 155 LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); 108 return ThreadIdentifier();156 return 0; 109 157 } 110 158 thread->start(); … … 112 160 QThread* threadRef = static_cast<QThread*>(thread); 113 161 114 return ThreadIdentifier(threadRef);162 return establishIdentifierForThread(threadRef); 115 163 } 116 164 … … 121 169 int waitForThreadCompletion(ThreadIdentifier threadID, void** result) 122 170 { 123 ASSERT(threadID .IsValid());124 125 QThread* thread = thread ID.platformId();171 ASSERT(threadID); 172 173 QThread* thread = threadForIdentifier(threadID); 126 174 127 175 bool res = thread->wait(); 128 176 177 clearThreadForIdentifier(threadID); 129 178 if (result) 130 179 *result = static_cast<ThreadPrivate*>(thread)->getReturnValue(); … … 139 188 ThreadIdentifier currentThread() 140 189 { 141 return ThreadIdentifier(QThread::currentThread()); 190 QThread* currentThread = QThread::currentThread(); 191 if (ThreadIdentifier id = identifierByQthreadHandle(currentThread)) 192 return id; 193 return establishIdentifierForThread(currentThread); 142 194 } 143 195
Note:
See TracChangeset
for help on using the changeset viewer.