Changeset 43392 in webkit for trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp
- Timestamp:
- May 7, 2009, 11:47:19 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp
r43366 r43392 43 43 namespace WTF { 44 44 45 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const46 {47 return m_platformId == another.m_platformId;48 }49 50 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const51 {52 return m_platformId != another.m_platformId;53 }54 55 45 static Mutex* atomicallyInitializedStaticMutex; 56 46 57 47 static ThreadIdentifier mainThreadIdentifier; 48 49 static Mutex& threadMapMutex() 50 { 51 static Mutex mutex; 52 return mutex; 53 } 58 54 59 55 void initializeThreading() … … 65 61 if (!atomicallyInitializedStaticMutex) { 66 62 atomicallyInitializedStaticMutex = new Mutex; 63 threadMapMutex(); 67 64 initializeRandomNumberGenerator(); 68 65 mainThreadIdentifier = currentThread(); … … 82 79 } 83 80 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 84 129 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*) 85 130 { … … 87 132 if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) { 88 133 LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); 89 return ThreadIdentifier(); 90 } 91 92 return ThreadIdentifier(thread); 134 return 0; 135 } 136 137 ThreadIdentifier threadID = establishIdentifierForThread(thread); 138 return threadID; 93 139 } 94 140 … … 99 145 int waitForThreadCompletion(ThreadIdentifier threadID, void** result) 100 146 { 101 ASSERT(threadID .isValid());102 103 GThread* thread = thread ID.platformId();147 ASSERT(threadID); 148 149 GThread* thread = threadForIdentifier(threadID); 104 150 105 151 void* joinResult = g_thread_join(thread); … … 107 153 *result = joinResult; 108 154 155 clearThreadForIdentifier(threadID); 109 156 return 0; 110 157 } … … 116 163 ThreadIdentifier currentThread() 117 164 { 118 return ThreadIdentifier(g_thread_self()); 165 GThread* currentThread = g_thread_self(); 166 if (ThreadIdentifier id = identifierByGthreadHandle(currentThread)) 167 return id; 168 return establishIdentifierForThread(currentThread); 119 169 } 120 170
Note:
See TracChangeset
for help on using the changeset viewer.