haikuwebkit/Source/WTF/wtf/ObjectIdentifier.cpp

49 lines
1.8 KiB
C++
Raw Permalink Normal View History

Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated https://bugs.webkit.org/show_bug.cgi?id=193848 Reviewed by Youenn Fablet. Source/WebCore: * dom/Document.cpp: * dom/MessageChannel.cpp: (WebCore::MessageChannel::MessageChannel): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::contextIdentifier const): * history/HistoryItem.cpp: (WebCore::HistoryItem::HistoryItem): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::registerTemporaryServiceWorkerClient): * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * platform/Process.cpp: (WebCore::Process::identifier): * workers/service/ServiceWorkerJobData.cpp: (WebCore::ServiceWorkerJobData::ServiceWorkerJobData): * workers/service/server/RegistrationDatabase.cpp: (WebCore::RegistrationDatabase::importRecords): * workers/service/server/SWServer.cpp: (WebCore::SWServer::Connection::Connection): (WebCore::SWServer::updateWorker): * workers/service/server/SWServerRegistration.cpp: (WebCore::generateServiceWorkerRegistrationIdentifier): * workers/service/server/SWServerToContextConnection.cpp: (WebCore::generateServerToContextConnectionIdentifier): Source/WebKit: * Platform/IPC/Connection.cpp: (IPC::Connection::Connection): * UIProcess/ChildProcessProxy.h: * UIProcess/UserContent/WebUserContentControllerProxy.cpp: (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::restoreFromState): * UIProcess/WebProcessPool.cpp: * WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp: (WebKit::UserMediaPermissionRequestManager::addDeviceChangeObserver): Source/WTF: Move WTF::generateObjectIdentifier()'s internal counter out-of-line so make sure it never gets duplicated at each call site. This has caused some hard-to-debug issues with duplicate identifiers such as Bug 193761. Also move it to ObjectIdentifier and rename it to generate() as this make call sites nicer when they have a typedef for the ObjectIdentifier<T> type. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/ObjectIdentifier.cpp: Copied from Source/WebCore/platform/Process.cpp. (WTF::ObjectIdentifierBase::generateIdentifierInternal): (WTF::ObjectIdentifierBase::generateThreadSafeIdentifierInternal): * wtf/ObjectIdentifier.h: (WTF::ObjectIdentifier::generate): (WTF::ObjectIdentifier::generateThreadSafe): Canonical link: https://commits.webkit.org/208459@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240661 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-29 17:50:53 +00:00
/*
* Copyright (C) 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ObjectIdentifier.h"
namespace WTF {
uint64_t ObjectIdentifierBase::generateIdentifierInternal()
{
static uint64_t current;
return ++current;
}
uint64_t ObjectIdentifierBase::generateThreadSafeIdentifierInternal()
{
static LazyNeverDestroyed<std::atomic<uint64_t>> current;
static std::once_flag initializeCurrentIdentifier;
std::call_once(initializeCurrentIdentifier, [] {
current.construct(0);
});
return ++current.get();
}
} // namespace WTF