Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Unified Diff: third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp

Issue 2134323002: Remove threading primitives from ParseHTMLOnMainThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on 405128 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp b/third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp
index 7adda766265691e9b4e2a725ed1e97bf9327faa6..77ac1d906a8710e3459074b6167e387535ea5d00 100644
--- a/third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp
+++ b/third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp
@@ -4,12 +4,38 @@
#include "core/html/parser/ParsedChunkQueue.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include <algorithm>
#include <memory>
namespace blink {
+namespace {
+
+// TODO(csharrison): Remove this temporary class when the ParseHTMLOnMainThread
+// experiment ends.
+class MaybeLocker {
+public:
+ MaybeLocker(Mutex* mutex)
+ : m_mutex(mutex)
+ {
+ if (m_mutex)
+ m_mutex->lock();
+ }
+ ~MaybeLocker()
+ {
+ if (m_mutex)
+ m_mutex->unlock();
+ }
+
+private:
+ Mutex* m_mutex;
+};
+
+} // namespace
+
ParsedChunkQueue::ParsedChunkQueue()
+ : m_mutex(RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled() ? nullptr : new Mutex)
{
}
@@ -19,7 +45,7 @@ ParsedChunkQueue::~ParsedChunkQueue()
bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk> chunk)
{
- MutexLocker locker(m_mutex);
+ MaybeLocker locker(m_mutex.get());
m_pendingTokenCount += chunk->tokens->size();
m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCount);
@@ -33,7 +59,7 @@ bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk>
void ParsedChunkQueue::clear()
{
- MutexLocker locker(m_mutex);
+ MaybeLocker locker(m_mutex.get());
m_pendingTokenCount = 0;
m_pendingChunks.clear();
@@ -41,7 +67,7 @@ void ParsedChunkQueue::clear()
void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::ParsedChunk>>& vector)
{
- MutexLocker locker(m_mutex);
+ MaybeLocker locker(m_mutex.get());
ASSERT(vector.isEmpty());
m_pendingChunks.swap(vector);
@@ -49,13 +75,13 @@ void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed
size_t ParsedChunkQueue::peakPendingChunkCount()
{
- MutexLocker locker(m_mutex);
+ MaybeLocker locker(m_mutex.get());
return m_peakPendingChunkCount;
}
size_t ParsedChunkQueue::peakPendingTokenCount()
{
- MutexLocker locker(m_mutex);
+ MaybeLocker locker(m_mutex.get());
return m_peakPendingTokenCount;
}
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698