Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit cde0c1a

Browse files
callOnMainThread should use the same queue as RunLoop::dispatch
https://bugs.webkit.org/show_bug.cgi?id=213830 Reviewed by Brady Eidson. Source/JavaScriptCore: * JavaScriptCore.order: Source/WTF: This should reduce flakiness in scheduled tasks. There's no need to keep a separate queue anymore since both APIs have the same semantics now. * wtf/MainThread.cpp: (WTF::callOnMainThread): (WTF::functionQueue): Deleted. (WTF::dispatchFunctionsFromMainThread): Deleted. * wtf/MainThread.h: * wtf/cocoa/MainThreadCocoa.mm: (WTF::scheduleDispatchFunctionsOnMainThread): Deleted. * wtf/generic/MainThreadGeneric.cpp: (WTF::scheduleDispatchFunctionsOnMainThread): Deleted. * wtf/win/MainThreadWin.cpp: (WTF::scheduleDispatchFunctionsOnMainThread): Deleted. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@263981 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent fefda94 commit cde0c1a

File tree

8 files changed

+39
-65
lines changed

8 files changed

+39
-65
lines changed

Source/JavaScriptCore/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2020-07-06 Geoffrey Garen <[email protected]>
2+
3+
callOnMainThread should use the same queue as RunLoop::dispatch
4+
https://bugs.webkit.org/show_bug.cgi?id=213830
5+
6+
Reviewed by Brady Eidson.
7+
8+
* JavaScriptCore.order:
9+
110
2020-07-05 Commit Queue <[email protected]>
211

312
Unreviewed, reverting r263960.

Source/JavaScriptCore/JavaScriptCore.order

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,6 @@ __ZN3JSC4Heap9unprotectENS_7JSValueE
10201020
__ZN3WTF7HashMapIPN3JSC6JSCellEjNS_7PtrHashIS3_EENS_10HashTraitsIS3_EENS6_IjEEE6removeENS_24HashTableIteratorAdapterINS_9HashTableIS3_NS_12KeyValuePairIS3_jEENS_24KeyValuePairKeyExtractorISD_EES5_NS_18HashMapValueTraitsIS7_S8_EES7_EESD_EE
10211021
__ZN3WTF21PageAllocationAligned10deallocateEv
10221022
-[JSWTFMainThreadCaller call]
1023-
__ZN3WTF31dispatchFunctionsFromMainThreadEv
10241023
__ZN3WTF7Unicode18convertUTF16ToUTF8EPPKtS2_PPcS4_b
10251024
__ZN3WTF25TCMalloc_Central_FreeList11ShrinkCacheEib
10261025
__ZN3WTF25TCMalloc_Central_FreeList18ReleaseListToSpansENS_11HardenedSLLE

Source/WTF/ChangeLog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2020-07-06 Geoffrey Garen <[email protected]>
2+
3+
callOnMainThread should use the same queue as RunLoop::dispatch
4+
https://bugs.webkit.org/show_bug.cgi?id=213830
5+
6+
Reviewed by Brady Eidson.
7+
8+
This should reduce flakiness in scheduled tasks.
9+
10+
There's no need to keep a separate queue anymore since both APIs have
11+
the same semantics now.
12+
13+
* wtf/MainThread.cpp:
14+
(WTF::callOnMainThread):
15+
(WTF::functionQueue): Deleted.
16+
(WTF::dispatchFunctionsFromMainThread): Deleted.
17+
* wtf/MainThread.h:
18+
* wtf/cocoa/MainThreadCocoa.mm:
19+
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
20+
* wtf/generic/MainThreadGeneric.cpp:
21+
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
22+
* wtf/win/MainThreadWin.cpp:
23+
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
24+
125
2020-07-06 Michael Catanzaro <[email protected]>
226

327
Spams system logs with "Current memory footprint: 10 MB"

Source/WTF/wtf/MainThread.cpp

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@
4141

4242
namespace WTF {
4343

44-
static Lock mainThreadFunctionQueueMutex;
45-
46-
static Deque<Function<void ()>>& functionQueue()
47-
{
48-
static NeverDestroyed<Deque<Function<void ()>>> functionQueue;
49-
return functionQueue;
50-
}
51-
5244
void initializeMainThread()
5345
{
5446
static std::once_flag initializeKey;
@@ -66,28 +58,6 @@ bool canCurrentThreadAccessThreadLocalData(Thread& thread)
6658
}
6759
#endif
6860

69-
void dispatchFunctionsFromMainThread()
70-
{
71-
ASSERT(isMainThread());
72-
73-
Function<void ()> function;
74-
75-
while (true) {
76-
{
77-
auto locker = holdLock(mainThreadFunctionQueueMutex);
78-
if (!functionQueue().size())
79-
break;
80-
81-
function = functionQueue().takeFirst();
82-
}
83-
84-
function();
85-
86-
// Clearing the function can have side effects, so do so outside of the lock above.
87-
function = nullptr;
88-
}
89-
}
90-
9161
bool isMainRunLoop()
9262
{
9363
return RunLoop::isMain();
@@ -100,18 +70,14 @@ void callOnMainRunLoop(Function<void()>&& function)
10070

10171
void callOnMainThread(Function<void()>&& function)
10272
{
103-
ASSERT(function);
104-
105-
bool needToSchedule = false;
106-
107-
{
108-
auto locker = holdLock(mainThreadFunctionQueueMutex);
109-
needToSchedule = functionQueue().size() == 0;
110-
functionQueue().append(WTFMove(function));
73+
#if USE(WEB_THREAD)
74+
if (auto* webRunLoop = RunLoop::webIfExists()) {
75+
webRunLoop->dispatch(WTFMove(function));
76+
return;
11177
}
78+
#endif
11279

113-
if (needToSchedule)
114-
scheduleDispatchFunctionsOnMainThread();
80+
RunLoop::main().dispatch(WTFMove(function));
11581
}
11682

11783
bool isMainThreadOrGCThread()

Source/WTF/wtf/MainThread.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ WTF_EXPORT_PRIVATE bool isMainThreadOrGCThread();
7272

7373
// NOTE: these functions are internal to the callOnMainThread implementation.
7474
void initializeMainThreadPlatform();
75-
void scheduleDispatchFunctionsOnMainThread();
76-
void dispatchFunctionsFromMainThread();
7775

7876
} // namespace WTF
7977

Source/WTF/wtf/cocoa/MainThreadCocoa.mm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ void initializeMainThreadPlatform()
6969
ASSERT(pthread_main_np());
7070
}
7171

72-
void scheduleDispatchFunctionsOnMainThread()
73-
{
74-
#if USE(WEB_THREAD)
75-
if (auto* webRunLoop = RunLoop::webIfExists()) {
76-
webRunLoop->dispatch(dispatchFunctionsFromMainThread);
77-
return;
78-
}
79-
#endif
80-
81-
RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
82-
}
83-
8472
void dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded(void (^block)())
8573
{
8674
#if USE(WEB_THREAD)

Source/WTF/wtf/generic/MainThreadGeneric.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,4 @@ bool isMainThread()
6060
#endif
6161
}
6262

63-
void scheduleDispatchFunctionsOnMainThread()
64-
{
65-
RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
66-
}
67-
6863
} // namespace WTF

Source/WTF/wtf/win/MainThreadWin.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,4 @@ bool isMainThread()
5151
return mainThread == Thread::currentID();
5252
}
5353

54-
void scheduleDispatchFunctionsOnMainThread()
55-
{
56-
RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
57-
}
58-
5954
} // namespace WTF

0 commit comments

Comments
 (0)