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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/html/parser/ParsedChunkQueue.h" 5 #include "core/html/parser/ParsedChunkQueue.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h"
7 #include <algorithm> 8 #include <algorithm>
8 #include <memory> 9 #include <memory>
9 10
10 namespace blink { 11 namespace blink {
11 12
13 namespace {
14
15 // TODO(csharrison): Remove this temporary class when the ParseHTMLOnMainThread
16 // experiment ends.
17 class MaybeLocker {
18 public:
19 MaybeLocker(Mutex* mutex)
20 : m_mutex(mutex)
21 {
22 if (m_mutex)
23 m_mutex->lock();
24 }
25 ~MaybeLocker()
26 {
27 if (m_mutex)
28 m_mutex->unlock();
29 }
30
31 private:
32 Mutex* m_mutex;
33 };
34
35 } // namespace
36
12 ParsedChunkQueue::ParsedChunkQueue() 37 ParsedChunkQueue::ParsedChunkQueue()
38 : m_mutex(RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled() ? nullptr : new Mutex)
13 { 39 {
14 } 40 }
15 41
16 ParsedChunkQueue::~ParsedChunkQueue() 42 ParsedChunkQueue::~ParsedChunkQueue()
17 { 43 {
18 } 44 }
19 45
20 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk> chunk) 46 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk> chunk)
21 { 47 {
22 MutexLocker locker(m_mutex); 48 MaybeLocker locker(m_mutex.get());
23 49
24 m_pendingTokenCount += chunk->tokens->size(); 50 m_pendingTokenCount += chunk->tokens->size();
25 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo unt); 51 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo unt);
26 52
27 bool wasEmpty = m_pendingChunks.isEmpty(); 53 bool wasEmpty = m_pendingChunks.isEmpty();
28 m_pendingChunks.append(std::move(chunk)); 54 m_pendingChunks.append(std::move(chunk));
29 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks. size()); 55 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks. size());
30 56
31 return wasEmpty; 57 return wasEmpty;
32 } 58 }
33 59
34 void ParsedChunkQueue::clear() 60 void ParsedChunkQueue::clear()
35 { 61 {
36 MutexLocker locker(m_mutex); 62 MaybeLocker locker(m_mutex.get());
37 63
38 m_pendingTokenCount = 0; 64 m_pendingTokenCount = 0;
39 m_pendingChunks.clear(); 65 m_pendingChunks.clear();
40 } 66 }
41 67
42 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed Chunk>>& vector) 68 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed Chunk>>& vector)
43 { 69 {
44 MutexLocker locker(m_mutex); 70 MaybeLocker locker(m_mutex.get());
45 71
46 ASSERT(vector.isEmpty()); 72 ASSERT(vector.isEmpty());
47 m_pendingChunks.swap(vector); 73 m_pendingChunks.swap(vector);
48 } 74 }
49 75
50 size_t ParsedChunkQueue::peakPendingChunkCount() 76 size_t ParsedChunkQueue::peakPendingChunkCount()
51 { 77 {
52 MutexLocker locker(m_mutex); 78 MaybeLocker locker(m_mutex.get());
53 return m_peakPendingChunkCount; 79 return m_peakPendingChunkCount;
54 } 80 }
55 81
56 size_t ParsedChunkQueue::peakPendingTokenCount() 82 size_t ParsedChunkQueue::peakPendingTokenCount()
57 { 83 {
58 MutexLocker locker(m_mutex); 84 MaybeLocker locker(m_mutex.get());
59 return m_peakPendingTokenCount; 85 return m_peakPendingTokenCount;
60 } 86 }
61 87
62 } // namespace blink 88 } // namespace blink
OLDNEW
« 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