diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Tools/DumpRenderTree/JavaScriptThreading.cpp | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Tools/DumpRenderTree/JavaScriptThreading.cpp')
-rw-r--r-- | Tools/DumpRenderTree/JavaScriptThreading.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/Tools/DumpRenderTree/JavaScriptThreading.cpp b/Tools/DumpRenderTree/JavaScriptThreading.cpp index 66de156c7..e2f9bade6 100644 --- a/Tools/DumpRenderTree/JavaScriptThreading.cpp +++ b/Tools/DumpRenderTree/JavaScriptThreading.cpp @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -36,22 +36,25 @@ #include <stdlib.h> #include <wtf/Assertions.h> #include <wtf/HashSet.h> +#include <wtf/Lock.h> +#include <wtf/Threading.h> +#include <wtf/ThreadingPrimitives.h> #include <wtf/Vector.h> static const size_t javaScriptThreadsCount = 4; static bool javaScriptThreadsShouldTerminate; static JSContextGroupRef javaScriptThreadsGroup; -static Mutex& javaScriptThreadsMutex() +static Lock& javaScriptThreadsMutex() { - DEFINE_STATIC_LOCAL(Mutex, staticMutex, ()); + DEPRECATED_DEFINE_STATIC_LOCAL(Lock, staticMutex, ()); return staticMutex; } typedef HashSet<ThreadIdentifier> ThreadSet; static ThreadSet& javaScriptThreads() { - DEFINE_STATIC_LOCAL(ThreadSet, staticJavaScriptThreads, ()); + DEPRECATED_DEFINE_STATIC_LOCAL(ThreadSet, staticJavaScriptThreads, ()); ASSERT(!javaScriptThreadsMutex().tryLock()); return staticJavaScriptThreads; } @@ -68,26 +71,26 @@ void runJavaScriptThread(void*) JSGlobalContextRef ctx; { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); ctx = JSGlobalContextCreateInGroup(javaScriptThreadsGroup, 0); } JSStringRef scriptRef; { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); scriptRef = JSStringCreateWithUTF8CString(script); } while (true) { { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); JSValueRef exception = 0; JSEvaluateScript(ctx, scriptRef, 0, 0, 1, &exception); ASSERT(!exception); } { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); const size_t valuesCount = 1024; JSValueRef values[valuesCount]; for (size_t i = 0; i < valuesCount; ++i) @@ -95,7 +98,7 @@ void runJavaScriptThread(void*) } { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); if (javaScriptThreadsShouldTerminate) break; } @@ -104,7 +107,7 @@ void runJavaScriptThread(void*) if (rand() % 5) continue; - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); ThreadIdentifier thread = currentThread(); detachThread(thread); javaScriptThreads().remove(thread); @@ -112,7 +115,7 @@ void runJavaScriptThread(void*) break; } - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); JSStringRelease(scriptRef); JSGarbageCollect(ctx); JSGlobalContextRelease(ctx); @@ -122,7 +125,7 @@ void startJavaScriptThreads() { javaScriptThreadsGroup = JSContextGroupCreate(); - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); for (size_t i = 0; i < javaScriptThreadsCount; ++i) javaScriptThreads().add(createThread(&runJavaScriptThread, 0, 0)); @@ -131,13 +134,13 @@ void startJavaScriptThreads() void stopJavaScriptThreads() { { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); javaScriptThreadsShouldTerminate = true; } Vector<ThreadIdentifier, javaScriptThreadsCount> threads; { - MutexLocker locker(javaScriptThreadsMutex()); + LockHolder locker(javaScriptThreadsMutex()); copyToVector(javaScriptThreads(), threads); ASSERT(threads.size() == javaScriptThreadsCount); } @@ -145,7 +148,10 @@ void stopJavaScriptThreads() for (size_t i = 0; i < javaScriptThreadsCount; ++i) waitForThreadCompletion(threads[i]); - javaScriptThreads().clear(); + { + LockHolder locker(javaScriptThreadsMutex()); + javaScriptThreads().clear(); + } JSContextGroupRelease(javaScriptThreadsGroup); } |