diff --git a/packages/react-native/Libraries/Image/RCTImageLoader.mm b/packages/react-native/Libraries/Image/RCTImageLoader.mm index 46b267ccccaa42..dac4ecc5fe40ac 100644 --- a/packages/react-native/Libraries/Image/RCTImageLoader.mm +++ b/packages/react-native/Libraries/Image/RCTImageLoader.mm @@ -32,11 +32,7 @@ static NSInteger RCTImageBytesForImage(UIImage *image) return image.images ? image.images.count * singleImageBytes : singleImageBytes; } -static uint64_t getNextImageRequestCount(void) -{ - static uint64_t requestCounter = 0; - return requestCounter++; -} +static auto currentRequestCount = std::atomic(0); static NSError *addResponseHeadersToError(NSError *originalError, NSHTTPURLResponse *response) { @@ -510,7 +506,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req auto cancelled = std::make_shared>(0); __block dispatch_block_t cancelLoad = nil; __block NSLock *cancelLoadLock = [NSLock new]; - NSString *requestId = [NSString stringWithFormat:@"%@-%llu", [[NSUUID UUID] UUIDString], getNextImageRequestCount()]; + NSString *requestId = [NSString stringWithFormat:@"%@-%llu", [[NSUUID UUID] UUIDString], currentRequestCount++]; void (^completionHandler)(NSError *, id, id, NSURLResponse *) = ^(NSError *error, id imageOrData, id imageMetadata, NSURLResponse *response) { diff --git a/packages/react-native/Libraries/Network/RCTNetworkTask.mm b/packages/react-native/Libraries/Network/RCTNetworkTask.mm index 96a7ded6c9c8f4..c89e2b7b350aec 100644 --- a/packages/react-native/Libraries/Network/RCTNetworkTask.mm +++ b/packages/react-native/Libraries/Network/RCTNetworkTask.mm @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +#import #import #import @@ -20,6 +21,8 @@ @implementation RCTNetworkTask { RCTNetworkTask *_selfReference; } +static auto currentRequestId = std::atomic(0); + - (instancetype)initWithRequest:(NSURLRequest *)request handler:(id)handler callbackQueue:(dispatch_queue_t)callbackQueue @@ -28,10 +31,8 @@ - (instancetype)initWithRequest:(NSURLRequest *)request RCTAssertParam(handler); RCTAssertParam(callbackQueue); - static NSUInteger requestID = 0; - if ((self = [super init])) { - _requestID = @(requestID++); + _requestID = @(currentRequestId++); _request = request; _handler = handler; _callbackQueue = callbackQueue;