@@ -61,14 +61,15 @@ @implementation RCTInspectorDevServerHelper
61
61
RCT_NOT_IMPLEMENTED (-(instancetype )init)
62
62
63
63
static NSMutableDictionary<NSString *, RCTInspectorPackagerConnection *> *socketConnections = nil;
64
+ static NSLock *connectionsLock = [NSLock new ];
64
65
65
66
static void sendEventToAllConnections (NSString *event)
66
67
{
67
- @synchronized (socketConnections) { // [macOS]
68
- for (NSString *socketId in socketConnections) {
69
- [socketConnections[socketId] sendEventToAllConnections: event];
70
- }
68
+ [connectionsLock lock ]; // [macOS]
69
+ for (NSString *socketId in socketConnections) {
70
+ [socketConnections[socketId] sendEventToAllConnections: event];
71
71
}
72
+ [connectionsLock unlock ]; // [macOS]
72
73
}
73
74
74
75
+ (void )openDebugger : (NSURL *)bundleURL withErrorMessage : (NSString *)errorMessage
@@ -103,11 +104,11 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL
103
104
// Note, using a static dictionary isn't really the greatest design, but
104
105
// the packager connection does the same thing, so it's at least consistent.
105
106
// This is a static map that holds different inspector clients per the inspectorURL
106
- @synchronized (socketConnections) { // [macOS]
107
- if (socketConnections == nil ) {
108
- socketConnections = [NSMutableDictionary new ];
109
- }
107
+ [connectionsLock lock ]; // [macOS]
108
+ if (socketConnections == nil ) {
109
+ socketConnections = [NSMutableDictionary new ];
110
110
}
111
+ [connectionsLock unlock ]; // [macOS]
111
112
112
113
NSString *key = [inspectorURL absoluteString ];
113
114
// [macOS safety check to avoid a crash
@@ -119,20 +120,21 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL
119
120
120
121
RCTInspectorPackagerConnection *connection;
121
122
122
- @synchronized (socketConnections) { // [macOS]
123
- connection = socketConnections[key];
124
- if (!connection || !connection.isConnected ) {
125
- connection = [[RCTInspectorPackagerConnection alloc ] initWithURL: inspectorURL];
126
- // [macOS safety check to avoid a crash
127
- if (connection == nil ) {
128
- RCTLogError (@" failed to initialize RCTInspectorPackagerConnection" );
129
- return nil ;
130
- }
131
- // macOS]
123
+ [connectionsLock lock ]; // [macOS]
124
+ connection = socketConnections[key];
125
+ if (!connection || !connection.isConnected ) {
126
+ connection = [[RCTInspectorPackagerConnection alloc ] initWithURL: inspectorURL];
127
+ // [macOS safety check to avoid a crash
128
+ if (connection != nil ) {
132
129
socketConnections[key] = connection;
133
130
[connection connect ];
131
+ } else {
132
+ RCTLogError (@" failed to initialize RCTInspectorPackagerConnection" );
134
133
}
134
+ // macOS]
135
+
135
136
}
137
+ [connectionsLock unlock ]; // [macOS]
136
138
137
139
return connection;
138
140
}
0 commit comments