Changeset 43366 in webkit for trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp
- Timestamp:
- May 7, 2009, 2:24:36 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp
r42858 r43366 42 42 namespace WTF { 43 43 44 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const 45 { 46 return m_platformId == another.m_platformId; 47 } 48 49 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const 50 { 51 return m_platformId != another.m_platformId; 52 } 53 44 54 class ThreadPrivate : public QThread { 45 55 public: … … 70 80 static ThreadIdentifier mainThreadIdentifier; 71 81 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 126 82 void initializeThreading() 127 83 { 128 84 if (!atomicallyInitializedStaticMutex) { 129 85 atomicallyInitializedStaticMutex = new Mutex; 130 threadMapMutex();131 86 initializeRandomNumberGenerator(); 132 QThread* mainThread = QCoreApplication::instance()->thread(); 133 mainThreadIdentifier = identifierByQthreadHandle(mainThread); 134 if (!mainThreadIdentifier) 135 mainThreadIdentifier = establishIdentifierForThread(mainThread); 87 mainThreadIdentifier = ThreadIdentifier(QCoreApplication::instance()->thread()); 136 88 initializeMainThread(); 137 89 } … … 154 106 if (!thread) { 155 107 LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); 156 return 0;108 return ThreadIdentifier(); 157 109 } 158 110 thread->start(); … … 160 112 QThread* threadRef = static_cast<QThread*>(thread); 161 113 162 return establishIdentifierForThread(threadRef);114 return ThreadIdentifier(threadRef); 163 115 } 164 116 … … 169 121 int waitForThreadCompletion(ThreadIdentifier threadID, void** result) 170 122 { 171 ASSERT(threadID );172 173 QThread* thread = thread ForIdentifier(threadID);123 ASSERT(threadID.IsValid()); 124 125 QThread* thread = threadID.platformId(); 174 126 175 127 bool res = thread->wait(); 176 128 177 clearThreadForIdentifier(threadID);178 129 if (result) 179 130 *result = static_cast<ThreadPrivate*>(thread)->getReturnValue(); … … 188 139 ThreadIdentifier currentThread() 189 140 { 190 QThread* currentThread = QThread::currentThread(); 191 if (ThreadIdentifier id = identifierByQthreadHandle(currentThread)) 192 return id; 193 return establishIdentifierForThread(currentThread); 141 return ThreadIdentifier(QThread::currentThread()); 194 142 } 195 143
Note:
See TracChangeset
for help on using the changeset viewer.