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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamerThread.cpp

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "bindings/core/v8/ScriptStreamerThread.h" 5 #include "bindings/core/v8/ScriptStreamerThread.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/ScriptStreamer.h" 8 #include "bindings/core/v8/ScriptStreamer.h"
9 #include "core/inspector/InspectorTraceEvents.h" 9 #include "core/inspector/InspectorTraceEvents.h"
10 #include "platform/WebTaskRunner.h" 10 #include "platform/WebTaskRunner.h"
11 #include "platform/instrumentation/tracing/TraceEvent.h" 11 #include "platform/instrumentation/tracing/TraceEvent.h"
12 #include "platform/wtf/PtrUtil.h" 12 #include "platform/wtf/PtrUtil.h"
13 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
14 #include "public/platform/WebTraceLocation.h" 14 #include "public/platform/WebTraceLocation.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 static ScriptStreamerThread* g_shared_thread = 0; 18 static ScriptStreamerThread* g_shared_thread = 0;
19 // Guards s_sharedThread. s_sharedThread is initialized and deleted in the main 19 // Guards s_sharedThread. s_sharedThread is initialized and deleted in the main
20 // thread, but also used by the streamer thread. Races can occur during 20 // thread, but also used by the streamer thread. Races can occur during
21 // shutdown. 21 // shutdown.
22 static Mutex* g_mutex = 0; 22 static Mutex* g_mutex = 0;
23 23
24 void ScriptStreamerThread::Init() { 24 void ScriptStreamerThread::Init() {
25 ASSERT(!g_shared_thread); 25 DCHECK(!g_shared_thread);
26 ASSERT(IsMainThread()); 26 DCHECK(IsMainThread());
27 // This is called in the main thread before any tasks are created, so no 27 // This is called in the main thread before any tasks are created, so no
28 // locking is needed. 28 // locking is needed.
29 g_mutex = new Mutex(); 29 g_mutex = new Mutex();
30 g_shared_thread = new ScriptStreamerThread(); 30 g_shared_thread = new ScriptStreamerThread();
31 } 31 }
32 32
33 ScriptStreamerThread* ScriptStreamerThread::Shared() { 33 ScriptStreamerThread* ScriptStreamerThread::Shared() {
34 return g_shared_thread; 34 return g_shared_thread;
35 } 35 }
36 36
37 void ScriptStreamerThread::PostTask(std::unique_ptr<CrossThreadClosure> task) { 37 void ScriptStreamerThread::PostTask(std::unique_ptr<CrossThreadClosure> task) {
38 ASSERT(IsMainThread()); 38 DCHECK(IsMainThread());
39 MutexLocker locker(mutex_); 39 MutexLocker locker(mutex_);
40 ASSERT(!running_task_); 40 DCHECK(!running_task_);
41 running_task_ = true; 41 running_task_ = true;
42 PlatformThread().GetWebTaskRunner()->PostTask(BLINK_FROM_HERE, 42 PlatformThread().GetWebTaskRunner()->PostTask(BLINK_FROM_HERE,
43 std::move(task)); 43 std::move(task));
44 } 44 }
45 45
46 void ScriptStreamerThread::TaskDone() { 46 void ScriptStreamerThread::TaskDone() {
47 MutexLocker locker(mutex_); 47 MutexLocker locker(mutex_);
48 ASSERT(running_task_); 48 DCHECK(running_task_);
49 running_task_ = false; 49 running_task_ = false;
50 } 50 }
51 51
52 WebThread& ScriptStreamerThread::PlatformThread() { 52 WebThread& ScriptStreamerThread::PlatformThread() {
53 if (!IsRunning()) { 53 if (!IsRunning()) {
54 thread_ = WTF::WrapUnique( 54 thread_ = WTF::WrapUnique(
55 Platform::Current()->CreateThread("ScriptStreamerThread")); 55 Platform::Current()->CreateThread("ScriptStreamerThread"));
56 } 56 }
57 return *thread_; 57 return *thread_;
58 } 58 }
(...skipping 10 matching lines...) Expand all
69 task->Run(); 69 task->Run();
70 streamer->StreamingCompleteOnBackgroundThread(); 70 streamer->StreamingCompleteOnBackgroundThread();
71 MutexLocker locker(*g_mutex); 71 MutexLocker locker(*g_mutex);
72 ScriptStreamerThread* thread = Shared(); 72 ScriptStreamerThread* thread = Shared();
73 if (thread) 73 if (thread)
74 thread->TaskDone(); 74 thread->TaskDone();
75 // If thread is 0, we're shutting down. 75 // If thread is 0, we're shutting down.
76 } 76 }
77 77
78 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698