mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[runtime] - switched most runtime code to use swift::Mutex and swift::Condition (see SR-946)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "swift/Basic/Lazy.h"
|
||||
#include "swift/Runtime/Concurrent.h"
|
||||
#include "swift/Runtime/Metadata.h"
|
||||
#include "swift/Runtime/Mutex.h"
|
||||
#include "Private.h"
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
@@ -29,7 +30,6 @@
|
||||
#endif
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <mutex>
|
||||
|
||||
using namespace swift;
|
||||
|
||||
@@ -242,11 +242,10 @@ static void _addImageProtocolConformancesBlock(const uint8_t *conformances,
|
||||
struct ConformanceState {
|
||||
ConcurrentMap<ConformanceCacheEntry> Cache;
|
||||
std::vector<ConformanceSection> SectionsToScan;
|
||||
pthread_mutex_t SectionsToScanLock;
|
||||
Mutex SectionsToScanLock;
|
||||
|
||||
ConformanceState() {
|
||||
SectionsToScan.reserve(16);
|
||||
pthread_mutex_init(&SectionsToScanLock, nullptr);
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
_initializeCallbacksToInspectDylib();
|
||||
#else
|
||||
@@ -291,9 +290,8 @@ static void
|
||||
_registerProtocolConformances(ConformanceState &C,
|
||||
const ProtocolConformanceRecord *begin,
|
||||
const ProtocolConformanceRecord *end) {
|
||||
pthread_mutex_lock(&C.SectionsToScanLock);
|
||||
ScopedLock guard(C.SectionsToScanLock);
|
||||
C.SectionsToScan.push_back(ConformanceSection{begin, end});
|
||||
pthread_mutex_unlock(&C.SectionsToScanLock);
|
||||
}
|
||||
|
||||
static void _addImageProtocolConformancesBlock(const uint8_t *conformances,
|
||||
@@ -565,7 +563,7 @@ recur:
|
||||
unsigned failedGeneration = ConformanceCacheGeneration;
|
||||
|
||||
// If we didn't have an up-to-date cache entry, scan the conformance records.
|
||||
pthread_mutex_lock(&C.SectionsToScanLock);
|
||||
C.SectionsToScanLock.lock();
|
||||
|
||||
// If we have no new information to pull in (and nobody else pulled in
|
||||
// new information while we waited on the lock), we're done.
|
||||
@@ -573,7 +571,7 @@ recur:
|
||||
if (failedGeneration != ConformanceCacheGeneration) {
|
||||
// Someone else pulled in new conformances while we were waiting.
|
||||
// Start over with our newly-populated cache.
|
||||
pthread_mutex_unlock(&C.SectionsToScanLock);
|
||||
C.SectionsToScanLock.unlock();
|
||||
type = origType;
|
||||
goto recur;
|
||||
}
|
||||
@@ -582,7 +580,7 @@ recur:
|
||||
// Save the failure for this type-protocol pair in the cache.
|
||||
C.cacheFailure(type, protocol);
|
||||
|
||||
pthread_mutex_unlock(&C.SectionsToScanLock);
|
||||
C.SectionsToScanLock.unlock();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -643,7 +641,7 @@ recur:
|
||||
}
|
||||
++ConformanceCacheGeneration;
|
||||
|
||||
pthread_mutex_unlock(&C.SectionsToScanLock);
|
||||
C.SectionsToScanLock.unlock();
|
||||
// Start over with our newly-populated cache.
|
||||
type = origType;
|
||||
goto recur;
|
||||
@@ -654,7 +652,7 @@ swift::_searchConformancesByMangledTypeName(const llvm::StringRef typeName) {
|
||||
auto &C = Conformances.get();
|
||||
const Metadata *foundMetadata = nullptr;
|
||||
|
||||
pthread_mutex_lock(&C.SectionsToScanLock);
|
||||
ScopedLock guard(C.SectionsToScanLock);
|
||||
|
||||
unsigned sectionIdx = 0;
|
||||
unsigned endSectionIdx = C.SectionsToScan.size();
|
||||
@@ -674,7 +672,5 @@ swift::_searchConformancesByMangledTypeName(const llvm::StringRef typeName) {
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&C.SectionsToScanLock);
|
||||
|
||||
return foundMetadata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user