Rename AtomicString to AtomString
[WebKit.git] / Source / WebCore / platform / ios / wak / WebCoreThread.mm
index 4a92bc6..195408d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,7 @@
 #import "config.h"
 #import "WebCoreThread.h"
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
 
 #import "CommonVM.h"
 #import "FloatingPointEnvironment.h"
 #import "RuntimeApplicationChecks.h"
 #import "ThreadGlobalData.h"
 #import "WAKWindow.h"
+#import "WKUtilities.h"
 #import "WebCoreThreadInternal.h"
 #import "WebCoreThreadMessage.h"
 #import "WebCoreThreadRun.h"
-#import "WKUtilities.h"
-
+#import <Foundation/NSInvocation.h>
 #import <JavaScriptCore/InitializeThreading.h>
 #import <JavaScriptCore/JSLock.h>
+#import <libkern/OSAtomic.h>
+#import <objc/runtime.h>
 #import <wtf/Assertions.h>
 #import <wtf/MainThread.h>
 #import <wtf/RecursiveLockAdapter.h>
 #import <wtf/RunLoop.h>
+#import <wtf/ThreadSpecific.h>
 #import <wtf/Threading.h>
-#import <wtf/text/AtomicString.h>
-
-#import <Foundation/NSInvocation.h>
-#import <libkern/OSAtomic.h>
-#import <objc/runtime.h>
+#import <wtf/spi/cocoa/objcSPI.h>
+#import <wtf/text/AtomString.h>
 
 #define LOG_MESSAGES 0
 #define LOG_WEB_LOCK 0
@@ -82,21 +82,11 @@ static void _WebThreadUnlock();
 
 @end
 
-using NSAutoreleasePoolMark = void*;
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern NSAutoreleasePoolMark NSPushAutoreleasePool(unsigned ignored);
-extern void NSPopAutoreleasePool(NSAutoreleasePoolMark token);
-#ifdef __cplusplus
-}
-#endif
-
 static RecursiveLock webLock;
 static Lock webThreadReleaseLock;
 static RecursiveLock webCoreReleaseLock;
 
-static NSAutoreleasePoolMark autoreleasePoolMark;
+static void* autoreleasePoolMark;
 static CFRunLoopRef webThreadRunLoop;
 static NSRunLoop* webThreadNSRunLoop;
 static pthread_t webThread;
@@ -104,7 +94,7 @@ static BOOL isWebThreadLocked;
 static BOOL webThreadStarted;
 static unsigned webThreadLockCount;
 
-static NSAutoreleasePoolMark savedAutoreleasePoolMark;
+static void* savedAutoreleasePoolMark;
 static BOOL isNestedWebThreadRunLoop;
 typedef enum {
     PushOrPopAutoreleasePool,
@@ -143,6 +133,8 @@ static void WebCoreObjCDeallocWithWebThreadLockImpl(id self, SEL _cmd);
 
 static NSMutableArray* sAsyncDelegates = nil;
 
+WEBCORE_EXPORT volatile unsigned webThreadDelegateMessageScopeCount = 0;
+
 static inline void SendMessage(NSInvocation* invocation)
 {
     [invocation invoke];
@@ -182,6 +174,16 @@ static void HandleDelegateSource(void*)
 #endif
 }
 
+class WebThreadDelegateMessageScope {
+public:
+    WebThreadDelegateMessageScope() { ++webThreadDelegateMessageScopeCount; }
+    ~WebThreadDelegateMessageScope()
+    {
+        ASSERT(webThreadDelegateMessageScopeCount);
+        --webThreadDelegateMessageScopeCount;
+    }
+};
+
 static void SendDelegateMessage(NSInvocation* invocation)
 {
     if (!WebThreadIsCurrent()) {
@@ -205,6 +207,7 @@ static void SendDelegateMessage(NSInvocation* invocation)
 #endif
 
     {
+        WebThreadDelegateMessageScope delegateScope;
         // Code block created to scope JSC::JSLock::DropAllLocks outside of WebThreadLock()
         JSC::JSLock::DropAllLocks dropAllLocks(WebCore::commonVM());
         _WebThreadUnlock();
@@ -465,7 +468,7 @@ static void WebRunLoopLockInternal(AutoreleasePoolOperation poolOperation)
 {
     _WebThreadLock();
     if (poolOperation == PushOrPopAutoreleasePool)
-        autoreleasePoolMark = NSPushAutoreleasePool(0);
+        autoreleasePoolMark = objc_autoreleasePoolPush();
     isWebThreadLocked = YES;
 }
 
@@ -479,7 +482,7 @@ static void WebRunLoopUnlockInternal(AutoreleasePoolOperation poolOperation)
     }
 
     if (poolOperation == PushOrPopAutoreleasePool)
-        NSPopAutoreleasePool(autoreleasePoolMark);
+        objc_autoreleasePoolPop(autoreleasePoolMark);
 
     _WebThreadUnlock();
     isWebThreadLocked = NO;
@@ -629,11 +632,11 @@ static void StartWebThread()
 {
     webThreadStarted = TRUE;
 
-    // ThreadGlobalData touches AtomicString, which requires Threading initialization.
+    // ThreadGlobalData touches AtomString, which requires Threading initialization.
     WTF::initializeThreading();
 
-    // Initialize AtomicString on the main thread.
-    WTF::AtomicString::init();
+    // Initialize AtomString on the main thread.
+    WTF::AtomString::init();
 
     // Initialize ThreadGlobalData on the main UI thread so that the WebCore thread
     // can later set it's thread-specific data to point to the same objects.
@@ -665,12 +668,9 @@ static void StartWebThread()
     // The web thread is a secondary thread, and secondary threads are usually given
     // a 512 kb stack, but we need more space in order to have room for the JavaScriptCore
     // reentrancy limit. This limit works on both the simulator and the device.
-    pthread_attr_setstacksize(&tattr, 200 * 4096);
+    pthread_attr_setstacksize(&tattr, 800 * KB);
 
-    struct sched_param param;
-    pthread_attr_getschedparam(&tattr, &param);
-    param.sched_priority--;
-    pthread_attr_setschedparam(&tattr, &param);
+    pthread_attr_set_qos_class_np(&tattr, QOS_CLASS_USER_INTERACTIVE, -10);
 
     // Wait for the web thread to startup completely before we continue.
     {
@@ -877,8 +877,10 @@ WebThreadContext* WebThreadCurrentContext(void)
 void WebThreadEnable(void)
 {
     RELEASE_ASSERT_WITH_MESSAGE(!WebCore::IOSApplication::isWebProcess(), "The WebProcess should never run a Web Thread");
-    if (WebCore::IOSApplication::isSpringBoard())
+    if (WebCore::IOSApplication::isSpringBoard()) {
+        using WebCore::LogThreading;
         RELEASE_LOG_FAULT(Threading, "SpringBoard enabled WebThread.");
+    }
 
     static std::once_flag flag;
     std::call_once(flag, StartWebThread);
@@ -899,4 +901,4 @@ bool WebThreadNotCurrent(void)
     return webThreadStarted && !pthread_equal(webThread, pthread_self());
 }
 
-#endif // PLATFORM(IOS)
+#endif // PLATFORM(IOS_FAMILY)