Reviewed by Adam Roben.
http://bugs.webkit.org/show_bug.cgi?id=15939
Adds a currentThread API for use by SQLiteDatabase, etc.
* platform/Threading.h:
* platform/ThreadingNone.cpp:
(WebCore::currentThread):
* platform/gtk/ThreadingGtk.cpp:
(WebCore::identifierByGthreadHandle):
(WebCore::):
* platform/pthreads/ThreadingPthreads.cpp:
(WebCore::identifierByPthreadHandle):
(WebCore::currentThread):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27707
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-11-11 Justin Haygood <jhaygood@reaktix.com>
+
+ Reviewed by Adam Roben.
+
+ http://bugs.webkit.org/show_bug.cgi?id=15939
+ Adds a currentThread API for use by SQLiteDatabase, etc.
+
+ * platform/Threading.h:
+ * platform/ThreadingNone.cpp:
+ (WebCore::currentThread):
+ * platform/gtk/ThreadingGtk.cpp:
+ (WebCore::identifierByGthreadHandle):
+ (WebCore::):
+ * platform/pthreads/ThreadingPthreads.cpp:
+ (WebCore::identifierByPthreadHandle):
+ (WebCore::currentThread):
+
2007-11-11 Dan Bernstein <mitz@apple.com>
Reviewed by Adam Roben.
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
typedef struct _GCond GCond;
#endif
+#if PLATFORM(QT)
+class QMutex;
+class QWaitCondition;
+#endif
+
#include <stdint.h>
namespace WebCore {
// Returns 0 if thread creation failed
ThreadIdentifier createThread(ThreadFunction, void*);
+ThreadIdentifier currentThread();
int waitForThreadCompletion(ThreadIdentifier, void**);
void detachThread(ThreadIdentifier);
#elif PLATFORM(GTK)
typedef GMutex* PlatformMutex;
typedef GCond* PlatformCondition;
+#elif PLATFORM(QT)
+typedef QMutex* PlatformMutex;
+typedef QWaitCondition* PlatformCondition;
#else
typedef void* PlatformMutex;
typedef void* PlatformCondition;
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
ThreadIdentifier createThread(ThreadFunction, void*) { return 0; }
int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
void detachThread(ThreadIdentifier) { }
+ThreadIdentifier currentThread() { return 0; }
Mutex::Mutex() {}
Mutex::~Mutex() {}
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
return identifierCount++;
}
+static ThreadIdentifier identifierByGthreadHandle(GThread*& thread)
+{
+ MutexLocker locker(threadMapMutex());
+
+ HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin();
+ for (; i != threadMap().end(); ++i) {
+ if (i->second == thread)
+ return i->first;
+ }
+
+ return 0;
+}
+
static GThread* threadForIdentifier(ThreadIdentifier id)
{
MutexLocker locker(threadMapMutex());
{
}
+ThreadIdentifier currentThread()
+{
+ GThread* currentThread = g_thread_self();
+ if (ThreadIdentifier id = identifierByGthreadHandle(currentThread))
+ return id;
+ return establishIdentifierForThread(currentThread);
+}
+
Mutex::Mutex()
: m_mutex(g_mutex_new())
{
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
return identifierCount++;
}
+static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle)
+{
+ MutexLocker locker(threadMapMutex());
+
+ HashMap<ThreadIdentifier, pthread_t>::iterator i = threadMap().begin();
+ for (; i != threadMap().end(); ++i) {
+ if (pthread_equal(i->second, pthreadHandle))
+ return i->first;
+ }
+
+ return 0;
+}
+
static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id)
{
MutexLocker locker(threadMapMutex());
clearPthreadHandleForIdentifier(threadID);
}
+ThreadIdentifier currentThread()
+{
+ pthread_t currentThread = pthread_self();
+ if (ThreadIdentifier id = identifierByPthreadHandle(currentThread))
+ return id;
+ return establishIdentifierForPthreadHandle(currentThread);
+}
+
Mutex::Mutex()
{
pthread_mutex_init(&m_mutex, NULL);