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

Side by Side Diff: Source/core/workers/WorkerThread.h

Issue 507873003: [Blink-Worker] WorkerThread fires idleHandler only at the end of processing all tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implemented new idleHandler firing logic. Created 6 years, 2 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 17 matching lines...) Expand all
28 #define WorkerThread_h 28 #define WorkerThread_h
29 29
30 #include "core/dom/ExecutionContextTask.h" 30 #include "core/dom/ExecutionContextTask.h"
31 #include "core/frame/csp/ContentSecurityPolicy.h" 31 #include "core/frame/csp/ContentSecurityPolicy.h"
32 #include "core/workers/WorkerGlobalScope.h" 32 #include "core/workers/WorkerGlobalScope.h"
33 #include "platform/SharedTimer.h" 33 #include "platform/SharedTimer.h"
34 #include "platform/WebThreadSupportingGC.h" 34 #include "platform/WebThreadSupportingGC.h"
35 #include "platform/weborigin/SecurityOrigin.h" 35 #include "platform/weborigin/SecurityOrigin.h"
36 #include "wtf/Forward.h" 36 #include "wtf/Forward.h"
37 #include "wtf/MessageQueue.h" 37 #include "wtf/MessageQueue.h"
38 #include "wtf/Noncopyable.h"
38 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
39 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
41 42
42 namespace blink { 43 namespace blink {
43 class WebWaitableEvent; 44 class WebWaitableEvent;
44 } 45 }
45 46
46 namespace blink { 47 namespace blink {
47 48
48 class KURL; 49 class KURL;
49 class WorkerGlobalScope; 50 class WorkerGlobalScope;
50 class WorkerInspectorController; 51 class WorkerInspectorController;
51 class WorkerLoaderProxy; 52 class WorkerLoaderProxy;
52 class WorkerReportingProxy; 53 class WorkerReportingProxy;
53 class WorkerSharedTimer; 54 class WorkerSharedTimer;
54 class WorkerThreadShutdownFinishTask; 55 class WorkerThreadShutdownFinishTask;
55 class WorkerThreadStartupData; 56 class WorkerThreadStartupData;
56 class WorkerThreadTask; 57 class WorkerThreadTask;
57 58
58 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG lobalScopeOnStart }; 59 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG lobalScopeOnStart };
59 60
60 61
61 class WorkerThread : public RefCounted<WorkerThread> { 62 class WorkerThread : public RefCounted<WorkerThread> {
63
64 class WorkerThreadTask : public blink::WebThread::Task {
jochen (gone - plz use gerrit) 2014/10/14 13:46:03 nit. move down to the provide section. it's also
65 WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED;
66 public:
67 static PassOwnPtr<WorkerThreadTask> create(WorkerThread&
68 , PassOwnPtr<ExecutionContextTask>, bool);
69
70 virtual ~WorkerThreadTask() { }
71 virtual void run() OVERRIDE;
72
73 void setIsIdleHandlerTask(bool isIdleHandlerTask) { m_isIdleHandlerT ask = isIdleHandlerTask; }
74 bool isIdleHandlerTask() const { return m_isIdleHandlerTask; }
75
76 private:
77 WorkerThreadTask(WorkerThread&
78 , PassOwnPtr<ExecutionContextTask>, bool);
79
80 WorkerThread& m_workerThread;
81 OwnPtr<ExecutionContextTask> m_task;
82 bool m_isInstrumented;
83 bool m_isIdleHandlerTask;
84 };
85
62 public: 86 public:
63 virtual ~WorkerThread(); 87 virtual ~WorkerThread();
64 88
65 virtual void start(); 89 virtual void start();
66 virtual void stop(); 90 virtual void stop();
67 91
68 // Can be used to wait for this worker thread to shut down. 92 // Can be used to wait for this worker thread to shut down.
69 // (This is signalled on the main thread, so it's assumed to be waited o n the worker context thread) 93 // (This is signalled on the main thread, so it's assumed to be waited o n the worker context thread)
70 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } 94 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); }
71 95
(...skipping 20 matching lines...) Expand all
92 116
93 // Number of active worker threads. 117 // Number of active worker threads.
94 static unsigned workerThreadCount(); 118 static unsigned workerThreadCount();
95 119
96 PlatformThreadId platformThreadId() const; 120 PlatformThreadId platformThreadId() const;
97 121
98 void interruptAndDispatchInspectorCommands(); 122 void interruptAndDispatchInspectorCommands();
99 void setWorkerInspectorController(WorkerInspectorController*); 123 void setWorkerInspectorController(WorkerInspectorController*);
100 124
101 protected: 125 protected:
126 int decrementAndReturnTaskCount();
127 void queueUpIdleHandlerNow(long long delayMs);
128 int taskCount() { return m_tasksCount; }
129
102 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBe RawPtr<WorkerThreadStartupData>); 130 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBe RawPtr<WorkerThreadStartupData>);
103 131
104 // Factory method for creating a new worker context for the thread. 132 // Factory method for creating a new worker context for the thread.
105 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScop e(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; 133 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScop e(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0;
106 134
107 virtual void postInitialize() { } 135 virtual void postInitialize() { }
108 136
109 private: 137 private:
110 friend class WorkerSharedTimer; 138 friend class WorkerSharedTimer;
111 friend class WorkerThreadShutdownFinishTask; 139 friend class WorkerThreadShutdownFinishTask;
(...skipping 20 matching lines...) Expand all
132 Mutex m_threadCreationMutex; 160 Mutex m_threadCreationMutex;
133 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 161 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
134 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; 162 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData;
135 163
136 // Used to signal thread shutdown. 164 // Used to signal thread shutdown.
137 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; 165 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent;
138 166
139 // Used to signal thread termination. 167 // Used to signal thread termination.
140 OwnPtr<blink::WebWaitableEvent> m_terminationEvent; 168 OwnPtr<blink::WebWaitableEvent> m_terminationEvent;
141 169
170 bool m_IdleHandlerTaskPosted;
171 volatile int m_tasksCount;
172
142 // FIXME: This has to be last because of crbug.com/401397 - the 173 // FIXME: This has to be last because of crbug.com/401397 - the
143 // WorkerThread might get deleted before it had a chance to properly 174 // WorkerThread might get deleted before it had a chance to properly
144 // shut down. By deleting the WebThread first, we can guarantee that 175 // shut down. By deleting the WebThread first, we can guarantee that
145 // no pending tasks on the thread might want to access any of the other 176 // no pending tasks on the thread might want to access any of the other
146 // members during the WorkerThread's destruction. 177 // members during the WorkerThread's destruction.
147 OwnPtr<WebThreadSupportingGC> m_thread; 178 OwnPtr<WebThreadSupportingGC> m_thread;
148 }; 179 };
149 180
150 } // namespace blink 181 } // namespace blink
151 182
152 #endif // WorkerThread_h 183 #endif // WorkerThread_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/workers/WorkerThread.cpp » ('j') | Source/core/workers/WorkerThread.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698