Process::setIdentifier() / Process::identifier() do not need a lock
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 17:51:33 +0000 (17:51 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 17:51:33 +0000 (17:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184544

Reviewed by Brady Eidson.

Process::setIdentifier() / Process::identifier() do not need a lock.
Process::setIdentifier() gets called in ChildProcess::initialize(),
before we start any background threads. It is then safe to query
this process identifier later on from background threads without
locks.

* platform/Process.cpp:
(WebCore::Process::setIdentifier):
(WebCore::Process::identifier):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230583 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/Process.cpp

index 3030160..8dda55b 100644 (file)
@@ -1,3 +1,20 @@
+2018-04-12  Chris Dumez  <cdumez@apple.com>
+
+        Process::setIdentifier() / Process::identifier() do not need a lock
+        https://bugs.webkit.org/show_bug.cgi?id=184544
+
+        Reviewed by Brady Eidson.
+
+        Process::setIdentifier() / Process::identifier() do not need a lock.
+        Process::setIdentifier() gets called in ChildProcess::initialize(),
+        before we start any background threads. It is then safe to query
+        this process identifier later on from background threads without
+        locks.
+
+        * platform/Process.cpp:
+        (WebCore::Process::setIdentifier):
+        (WebCore::Process::identifier):
+
 2018-04-12  Antoine Quint  <graouts@apple.com>
 
         Unreviewed, fix the Windows build.
index 843d036..6059747 100644 (file)
 #include "config.h"
 #include "Process.h"
 
-#include <wtf/Lock.h>
-#include <wtf/Locker.h>
 #include <wtf/MainThread.h>
 
 namespace WebCore {
 namespace Process {
 
 static std::optional<ProcessIdentifier> globalIdentifier;
-static Lock globalIdentifierLock;
 
 void setIdentifier(ProcessIdentifier processIdentifier)
 {
     ASSERT(isMainThread());
-    Locker<Lock> locker(globalIdentifierLock);
     globalIdentifier = processIdentifier;
 }
 
@@ -47,12 +43,10 @@ ProcessIdentifier identifier()
 {
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
-        Locker<Lock> locker(globalIdentifierLock);
         if (!globalIdentifier)
             globalIdentifier = generateObjectIdentifier<ProcessIdentifierType>();
     });
 
-    Locker<Lock> locker(globalIdentifierLock);
     return *globalIdentifier;
 }