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

Side by Side Diff: third_party/WebKit/Source/platform/heap/GCTaskRunner.h

Issue 2550373005: Make WebTaskRunner ThreadSafeRefCounted (Closed)
Patch Set: +DISALLOW_COPY_AND_ASSIGN for win build fix Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 #include "platform/heap/ThreadState.h" 36 #include "platform/heap/ThreadState.h"
37 #include "public/platform/WebThread.h" 37 #include "public/platform/WebThread.h"
38 #include "public/platform/WebTraceLocation.h" 38 #include "public/platform/WebTraceLocation.h"
39 #include "wtf/PtrUtil.h" 39 #include "wtf/PtrUtil.h"
40 #include <memory> 40 #include <memory>
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class MessageLoopInterruptor final : public BlinkGCInterruptor { 44 class MessageLoopInterruptor final : public BlinkGCInterruptor {
45 public: 45 public:
46 explicit MessageLoopInterruptor(WebTaskRunner* taskRunner) 46 explicit MessageLoopInterruptor(RefPtr<WebTaskRunner> taskRunner)
47 : m_taskRunner(taskRunner) {} 47 : m_taskRunner(std::move(taskRunner)) {}
48 48
49 void requestInterrupt() override { 49 void requestInterrupt() override {
50 // GCTask has an empty run() method. Its only purpose is to guarantee 50 // GCTask has an empty run() method. Its only purpose is to guarantee
51 // that MessageLoop will have a task to process which will result 51 // that MessageLoop will have a task to process which will result
52 // in GCTaskRunner::didProcessTask being executed. 52 // in GCTaskRunner::didProcessTask being executed.
53 m_taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&runGCTask)); 53 m_taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&runGCTask));
54 } 54 }
55 55
56 private: 56 private:
57 static void runGCTask() { 57 static void runGCTask() {
58 // Don't do anything here because we don't know if this is 58 // Don't do anything here because we don't know if this is
59 // a nested event loop or not. GCTaskRunner::didProcessTask 59 // a nested event loop or not. GCTaskRunner::didProcessTask
60 // will enter correct safepoint for us. 60 // will enter correct safepoint for us.
61 // We are not calling onInterrupted() because that always 61 // We are not calling onInterrupted() because that always
62 // conservatively enters safepoint with pointers on stack. 62 // conservatively enters safepoint with pointers on stack.
63 } 63 }
64 64
65 WebTaskRunner* m_taskRunner; 65 RefPtr<WebTaskRunner> m_taskRunner;
66 }; 66 };
67 67
68 class GCTaskObserver final : public WebThread::TaskObserver { 68 class GCTaskObserver final : public WebThread::TaskObserver {
69 USING_FAST_MALLOC(GCTaskObserver); 69 USING_FAST_MALLOC(GCTaskObserver);
70 70
71 public: 71 public:
72 GCTaskObserver() : m_nesting(0) {} 72 GCTaskObserver() : m_nesting(0) {}
73 73
74 ~GCTaskObserver() { 74 ~GCTaskObserver() {
75 // m_nesting can be 1 if this was unregistered in a task and 75 // m_nesting can be 1 if this was unregistered in a task and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 ~GCTaskRunner() { m_thread->removeTaskObserver(m_gcTaskObserver.get()); } 110 ~GCTaskRunner() { m_thread->removeTaskObserver(m_gcTaskObserver.get()); }
111 111
112 private: 112 private:
113 std::unique_ptr<GCTaskObserver> m_gcTaskObserver; 113 std::unique_ptr<GCTaskObserver> m_gcTaskObserver;
114 WebThread* m_thread; 114 WebThread* m_thread;
115 }; 115 };
116 116
117 } // namespace blink 117 } // namespace blink
118 118
119 #endif 119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698