mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit8bcb71140f, reversing changes made toc4dd271d36.
This commit is contained in:
@@ -16,15 +16,14 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Runtime/Casting.h"
|
||||
#include "../CompatibilityOverride/CompatibilityOverride.h"
|
||||
#include "../SwiftShims/GlobalObjects.h"
|
||||
#include "../SwiftShims/RuntimeShims.h"
|
||||
#include "../SwiftShims/GlobalObjects.h"
|
||||
#include "../CompatibilityOverride/CompatibilityOverride.h"
|
||||
#include "ErrorObject.h"
|
||||
#include "ExistentialMetadataImpl.h"
|
||||
#include "Private.h"
|
||||
#include "SwiftHashableSupport.h"
|
||||
#include "swift/Basic/Lazy.h"
|
||||
#include "swift/Basic/Unreachable.h"
|
||||
#include "swift/Demangling/Demangler.h"
|
||||
#include "swift/Runtime/Config.h"
|
||||
#include "swift/Runtime/Debug.h"
|
||||
@@ -32,7 +31,13 @@
|
||||
#include "swift/Runtime/ExistentialContainer.h"
|
||||
#include "swift/Runtime/HeapObject.h"
|
||||
#include "swift/Runtime/Metadata.h"
|
||||
#include "swift/Threading/Mutex.h"
|
||||
#if defined(__wasi__)
|
||||
# define SWIFT_CASTING_SUPPORTS_MUTEX 0
|
||||
#else
|
||||
# define SWIFT_CASTING_SUPPORTS_MUTEX 1
|
||||
# include "swift/Runtime/Mutex.h"
|
||||
#endif
|
||||
#include "swift/Basic/Unreachable.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/PointerIntPair.h"
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
@@ -139,8 +144,10 @@ enum class TypeNameKind {
|
||||
|
||||
using TypeNameCacheKey = llvm::PointerIntPair<const Metadata *, 2, TypeNameKind>;
|
||||
|
||||
static LazyMutex TypeNameCacheLock;
|
||||
static LazyMutex MangledToPrettyFunctionNameCacheLock;
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
static StaticReadWriteLock TypeNameCacheLock;
|
||||
static StaticReadWriteLock MangledToPrettyFunctionNameCacheLock;
|
||||
#endif
|
||||
|
||||
/// Cache containing rendered names for Metadata.
|
||||
/// Access MUST be protected using `TypeNameCacheLock`.
|
||||
@@ -159,7 +166,9 @@ swift::swift_getTypeName(const Metadata *type, bool qualified) {
|
||||
|
||||
// Attempt read-only lookup of cache entry.
|
||||
{
|
||||
LazyMutex::ScopedLock guard(TypeNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedReadLock guard(TypeNameCacheLock);
|
||||
#endif
|
||||
|
||||
auto found = cache.find(key);
|
||||
if (found != cache.end()) {
|
||||
@@ -170,7 +179,9 @@ swift::swift_getTypeName(const Metadata *type, bool qualified) {
|
||||
|
||||
// Read-only lookup failed to find item, we may need to create it.
|
||||
{
|
||||
LazyMutex::ScopedLock guard(TypeNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedWriteLock guard(TypeNameCacheLock);
|
||||
#endif
|
||||
|
||||
// Do lookup again just to make sure it wasn't created by another
|
||||
// thread before we acquired the write lock.
|
||||
@@ -201,7 +212,9 @@ swift::swift_getMangledTypeName(const Metadata *type) {
|
||||
|
||||
// Attempt read-only lookup of cache entry.
|
||||
{
|
||||
LazyMutex::ScopedLock guard(TypeNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedReadLock guard(TypeNameCacheLock);
|
||||
#endif
|
||||
|
||||
auto found = cache.find(key);
|
||||
if (found != cache.end()) {
|
||||
@@ -212,7 +225,9 @@ swift::swift_getMangledTypeName(const Metadata *type) {
|
||||
|
||||
// Read-only cache lookup failed, we may need to create it.
|
||||
{
|
||||
LazyMutex::ScopedLock guard(TypeNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedWriteLock guard(TypeNameCacheLock);
|
||||
#endif
|
||||
|
||||
// Do lookup again just to make sure it wasn't created by another
|
||||
// thread before we acquired the write lock.
|
||||
@@ -255,7 +270,9 @@ swift::swift_getFunctionFullNameFromMangledName(
|
||||
auto &cache = MangledToPrettyFunctionNameCache.get();
|
||||
// Attempt read-only lookup of cache entry.
|
||||
{
|
||||
LazyMutex::ScopedLock guard(MangledToPrettyFunctionNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedReadLock guard(MangledToPrettyFunctionNameCacheLock);
|
||||
#endif
|
||||
|
||||
auto found = cache.find(mangledName);
|
||||
if (found != cache.end()) {
|
||||
@@ -370,7 +387,9 @@ swift::swift_getFunctionFullNameFromMangledName(
|
||||
result[size] = 0; // 0-terminated string
|
||||
|
||||
{
|
||||
LazyMutex::ScopedLock guard(MangledToPrettyFunctionNameCacheLock);
|
||||
#if SWIFT_CASTING_SUPPORTS_MUTEX
|
||||
StaticScopedWriteLock guard(MangledToPrettyFunctionNameCacheLock);
|
||||
#endif
|
||||
|
||||
cache.insert({mangledName, {result, size}});
|
||||
return TypeNamePair{result, size};
|
||||
|
||||
Reference in New Issue
Block a user