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

Unified Diff: third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp

Issue 2088333003: Make IdentifiersFactory thread-safe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: long -> int Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/inspector/IdentifiersFactory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp
diff --git a/third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp b/third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp
index 5482e92ca76be424f6a670383041b077d9a05008..e88630d5903d366317d24dc9df3d61bf81fbd67c 100644
--- a/third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp
+++ b/third_party/WebKit/Source/core/inspector/IdentifiersFactory.cpp
@@ -37,33 +37,16 @@ namespace blink {
namespace {
-static long s_lastUsedIdentifier = 0;
-
-// static
-String& processIdPrefix()
-{
- DEFINE_STATIC_LOCAL(String, s_processIdPrefix, ());
- return s_processIdPrefix;
-}
+volatile int s_lastUsedIdentifier = 0;
} // namespace
// static
-void IdentifiersFactory::initialize()
-{
- StringBuilder builder;
-
- builder.appendNumber(Platform::current()->getUniqueIdForProcess());
- builder.append('.');
- ASSERT(processIdPrefix().isEmpty() || processIdPrefix() == builder.toString());
- processIdPrefix() = builder.toString();
-}
-
-// static
String IdentifiersFactory::createIdentifier()
{
- return addProcessIdPrefixTo(++s_lastUsedIdentifier);
+ int identifier = atomicIncrement(&s_lastUsedIdentifier);
+ return addProcessIdPrefixTo(identifier);
}
// static
@@ -110,19 +93,27 @@ DocumentLoader* IdentifiersFactory::loaderById(InspectedFrames* inspectedFrames,
// static
String IdentifiersFactory::addProcessIdPrefixTo(int id)
{
- if (processIdPrefix().isEmpty())
- initialize();
- return processIdPrefix() + String::number(id);
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(uint32_t, s_processId, new uint32_t(Platform::current()->getUniqueIdForProcess()));
+
+ StringBuilder builder;
+
+ builder.appendNumber(s_processId);
+ builder.append('.');
+ builder.appendNumber(id);
+
+ return builder.toString();
}
// static
int IdentifiersFactory::removeProcessIdPrefixFrom(const String& id, bool* ok)
{
- if (id.length() < processIdPrefix().length()) {
+ size_t dotIndex = id.find('.');
+
+ if (dotIndex == kNotFound) {
*ok = false;
return 0;
}
- return id.substring(processIdPrefix().length()).toInt(ok);
+ return id.substring(dotIndex + 1).toInt(ok);
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/inspector/IdentifiersFactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698