Title: [225034] trunk/Source/WTF
Revision
225034
Author
[email protected]
Date
2017-11-19 13:56:17 -0800 (Sun, 19 Nov 2017)

Log Message

Fix potential thread safety issue in generateThreadSafeObjectIdentifier()
https://bugs.webkit.org/show_bug.cgi?id=179877

Reviewed by Sam Weinig.

Fix potential thread safety issue in generateThreadSafeObjectIdentifier().
Protect std::atomic initialization with an std::call_once() given that we
build with --fno-threadsafe-statics.

* wtf/ObjectIdentifier.h:
(WTF::generateThreadSafeObjectIdentifier):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (225033 => 225034)


--- trunk/Source/WTF/ChangeLog	2017-11-19 08:19:42 UTC (rev 225033)
+++ trunk/Source/WTF/ChangeLog	2017-11-19 21:56:17 UTC (rev 225034)
@@ -1,3 +1,17 @@
+2017-11-19  Chris Dumez  <[email protected]>
+
+        Fix potential thread safety issue in generateThreadSafeObjectIdentifier()
+        https://bugs.webkit.org/show_bug.cgi?id=179877
+
+        Reviewed by Sam Weinig.
+
+        Fix potential thread safety issue in generateThreadSafeObjectIdentifier().
+        Protect std::atomic initialization with an std::call_once() given that we
+        build with --fno-threadsafe-statics.
+
+        * wtf/ObjectIdentifier.h:
+        (WTF::generateThreadSafeObjectIdentifier):
+
 2017-11-18  Yusuke Suzuki  <[email protected]>
 
         [WTF] Use system endianess information instead of relying CPU information

Modified: trunk/Source/WTF/wtf/ObjectIdentifier.h (225033 => 225034)


--- trunk/Source/WTF/wtf/ObjectIdentifier.h	2017-11-19 08:19:42 UTC (rev 225033)
+++ trunk/Source/WTF/wtf/ObjectIdentifier.h	2017-11-19 21:56:17 UTC (rev 225034)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <atomic>
+#include <mutex>
 #include <wtf/HashTraits.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
@@ -99,7 +100,11 @@
 
 template<typename T> inline ObjectIdentifier<T> generateThreadSafeObjectIdentifier()
 {
-    static NeverDestroyed<std::atomic<uint64_t>> currentIdentifier;
+    static LazyNeverDestroyed<std::atomic<uint64_t>> currentIdentifier;
+    static std::once_flag initializeCurrentIdentifier;
+    std::call_once(initializeCurrentIdentifier, [] {
+        currentIdentifier.construct(0);
+    });
     return ObjectIdentifier<T> { ++currentIdentifier.get() };
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to