~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to JavaScriptCore/wtf/Threading.h

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
#include <wtf/GOwnPtr.h>
86
86
typedef struct _GMutex GMutex;
87
87
typedef struct _GCond GCond;
 
88
typedef struct _GThread GThread;
88
89
#endif
89
90
 
90
91
#if PLATFORM(QT)
91
92
#include <qglobal.h>
92
93
QT_BEGIN_NAMESPACE
93
94
class QMutex;
 
95
class QThread;
94
96
class QWaitCondition;
95
97
QT_END_NAMESPACE
96
98
#endif
105
107
 
106
108
namespace WTF {
107
109
 
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
 
 
127
110
#if USE(PTHREADS)
128
111
typedef pthread_mutex_t PlatformMutex;
129
112
typedef pthread_cond_t PlatformCondition;
 
113
typedef pthread_t PlatformThreadIdentifier;
130
114
#elif PLATFORM(GTK)
131
115
typedef GOwnPtr<GMutex> PlatformMutex;
132
116
typedef GOwnPtr<GCond> PlatformCondition;
 
117
typedef GThread* PlatformThreadIdentifier;
133
118
#elif PLATFORM(QT)
134
119
typedef QT_PREPEND_NAMESPACE(QMutex)* PlatformMutex;
135
120
typedef QT_PREPEND_NAMESPACE(QWaitCondition)* PlatformCondition;
 
121
typedef QT_PREPEND_NAMESPACE(QThread)* PlatformThreadIdentifier;
136
122
#elif PLATFORM(WIN_OS)
137
123
struct PlatformMutex {
138
124
    CRITICAL_SECTION m_internalMutex;
149
135
    bool timedWait(PlatformMutex&, DWORD durationMilliseconds);
150
136
    void signal(bool unblockAll);
151
137
};
 
138
typedef unsigned PlatformThreadIdentifier;
152
139
#else
153
140
typedef void* PlatformMutex;
154
141
typedef void* PlatformCondition;
155
142
#endif
156
143
    
 
144
// Platform-independent wrapper for thread id. Assignable and copyable.
 
145
// A valid ThreadIdentifier is usually returned from createThread(...) or currentThread() functions.
 
146
// ThreadIdentifier remains valid for as long as its thread is alive and is not automatically invalidated
 
147
// when thread terminates. Since platform-dependent thread ids can be recycled, stale ThreadIdentifier
 
148
// 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
 
157
193
class Mutex : Noncopyable {
158
194
public:
159
195
    Mutex();