Changeset 43392 in webkit for trunk/JavaScriptCore/wtf/Threading.h
- Timestamp:
- May 7, 2009, 11:47:19 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/Threading.h
r43366 r43392 86 86 typedef struct _GMutex GMutex; 87 87 typedef struct _GCond GCond; 88 typedef struct _GThread GThread;89 88 #endif 90 89 … … 93 92 QT_BEGIN_NAMESPACE 94 93 class QMutex; 95 class QThread;96 94 class QWaitCondition; 97 95 QT_END_NAMESPACE … … 108 106 namespace WTF { 109 107 108 typedef uint32_t ThreadIdentifier; 109 typedef void* (*ThreadFunction)(void* argument); 110 111 // Returns 0 if thread creation failed. 112 // The thread name must be a literal since on some platforms it's passed in to the thread. 113 ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName); 114 115 // Internal platform-specific createThread implementation. 116 ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName); 117 118 // Called in the thread during initialization. 119 // Helpful for platforms where the thread name must be set from within the thread. 120 void setThreadNameInternal(const char* threadName); 121 122 ThreadIdentifier currentThread(); 123 bool isMainThread(); 124 int waitForThreadCompletion(ThreadIdentifier, void**); 125 void detachThread(ThreadIdentifier); 126 110 127 #if USE(PTHREADS) 111 128 typedef pthread_mutex_t PlatformMutex; 112 129 typedef pthread_cond_t PlatformCondition; 113 typedef pthread_t PlatformThreadIdentifier;114 130 #elif PLATFORM(GTK) 115 131 typedef GOwnPtr<GMutex> PlatformMutex; 116 132 typedef GOwnPtr<GCond> PlatformCondition; 117 typedef GThread* PlatformThreadIdentifier;118 133 #elif PLATFORM(QT) 119 134 typedef QT_PREPEND_NAMESPACE(QMutex)* PlatformMutex; 120 135 typedef QT_PREPEND_NAMESPACE(QWaitCondition)* PlatformCondition; 121 typedef QT_PREPEND_NAMESPACE(QThread)* PlatformThreadIdentifier;122 136 #elif PLATFORM(WIN_OS) 123 137 struct PlatformMutex { … … 136 150 void signal(bool unblockAll); 137 151 }; 138 typedef unsigned PlatformThreadIdentifier;139 152 #else 140 153 typedef void* PlatformMutex; … … 142 155 #endif 143 156 144 // Platform-independent wrapper for thread id. Assignable and copyable.145 // The only way to obtain a valid ThreadIdentifier is from createThread(...) or currentThread() functions.146 // ThreadIdentifier remains valid for as long as its thread is alive and is not automatically invalidated147 // when thread terminates. Since platform-dependent thread ids can be recycled, stale ThreadIdentifier148 // may reference a completely unrelated thread after its original thread terminates.149 class ThreadIdentifier {150 public:151 ThreadIdentifier()152 : m_platformId(0)153 {154 ASSERT(!isValid());155 }156 157 explicit ThreadIdentifier(PlatformThreadIdentifier platformId)158 : m_platformId(platformId)159 {160 ASSERT(isValid());161 }162 163 bool isValid() const { return m_platformId; }164 void invalidate() { m_platformId = 0; }165 166 bool operator==(const ThreadIdentifier&) const;167 bool operator!=(const ThreadIdentifier&) const;168 169 PlatformThreadIdentifier platformId() const { return m_platformId; }170 171 private:172 PlatformThreadIdentifier m_platformId;173 };174 175 typedef void* (*ThreadFunction)(void* argument);176 177 // Returns invalid identifier if thread creation failed.178 // The thread name must be a literal since on some platforms it's passed in to the thread.179 ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);180 181 // Internal platform-specific createThread implementation.182 ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);183 184 // Called in the thread during initialization.185 // Helpful for platforms where the thread name must be set from within the thread.186 void setThreadNameInternal(const char* threadName);187 188 ThreadIdentifier currentThread();189 bool isMainThread();190 int waitForThreadCompletion(ThreadIdentifier, void**);191 void detachThread(ThreadIdentifier);192 193 157 class Mutex : Noncopyable { 194 158 public:
Note:
See TracChangeset
for help on using the changeset viewer.