Changeset 43366 in webkit for trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp
- Timestamp:
- May 7, 2009, 2:24:36 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp
r42857 r43366 43 43 namespace WTF { 44 44 45 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const 46 { 47 return m_platformId == another.m_platformId; 48 } 49 50 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const 51 { 52 return m_platformId != another.m_platformId; 53 } 54 45 55 static Mutex* atomicallyInitializedStaticMutex; 46 56 47 57 static ThreadIdentifier mainThreadIdentifier; 48 49 static Mutex& threadMapMutex()50 {51 static Mutex mutex;52 return mutex;53 }54 58 55 59 void initializeThreading() … … 61 65 if (!atomicallyInitializedStaticMutex) { 62 66 atomicallyInitializedStaticMutex = new Mutex; 63 threadMapMutex();64 67 initializeRandomNumberGenerator(); 65 68 mainThreadIdentifier = currentThread(); … … 79 82 } 80 83 81 static HashMap<ThreadIdentifier, GThread*>& threadMap()82 {83 static HashMap<ThreadIdentifier, GThread*> map;84 return map;85 }86 87 static ThreadIdentifier identifierByGthreadHandle(GThread*& thread)88 {89 MutexLocker locker(threadMapMutex());90 91 HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin();92 for (; i != threadMap().end(); ++i) {93 if (i->second == thread)94 return i->first;95 }96 97 return 0;98 }99 100 static ThreadIdentifier establishIdentifierForThread(GThread*& thread)101 {102 ASSERT(!identifierByGthreadHandle(thread));103 104 MutexLocker locker(threadMapMutex());105 106 static ThreadIdentifier identifierCount = 1;107 108 threadMap().add(identifierCount, thread);109 110 return identifierCount++;111 }112 113 static GThread* threadForIdentifier(ThreadIdentifier id)114 {115 MutexLocker locker(threadMapMutex());116 117 return threadMap().get(id);118 }119 120 static void clearThreadForIdentifier(ThreadIdentifier id)121 {122 MutexLocker locker(threadMapMutex());123 124 ASSERT(threadMap().contains(id));125 126 threadMap().remove(id);127 }128 129 84 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*) 130 85 { … … 132 87 if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) { 133 88 LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); 134 return 0;89 return ThreadIdentifier(); 135 90 } 136 91 137 ThreadIdentifier threadID = establishIdentifierForThread(thread); 138 return threadID; 92 return ThreadIdentifier(thread); 139 93 } 140 94 … … 145 99 int waitForThreadCompletion(ThreadIdentifier threadID, void** result) 146 100 { 147 ASSERT(threadID );101 ASSERT(threadID.isValid()); 148 102 149 GThread* thread = thread ForIdentifier(threadID);103 GThread* thread = threadID.platformId(); 150 104 151 105 void* joinResult = g_thread_join(thread); … … 153 107 *result = joinResult; 154 108 155 clearThreadForIdentifier(threadID);156 109 return 0; 157 110 } … … 163 116 ThreadIdentifier currentThread() 164 117 { 165 GThread* currentThread = g_thread_self(); 166 if (ThreadIdentifier id = identifierByGthreadHandle(currentThread)) 167 return id; 168 return establishIdentifierForThread(currentThread); 118 return ThreadIdentifier(g_thread_self()); 169 119 } 170 120
Note:
See TracChangeset
for help on using the changeset viewer.