From 3d9748f88ec167b6226f51d49eb16a890c337813 Mon Sep 17 00:00:00 2001 From: Kushagra Date: Tue, 29 Oct 2024 13:41:40 +0530 Subject: [PATCH] Added push and pop validation in synchronized block --- CleverTapSDK/CTValidationResultStack.m | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/CleverTapSDK/CTValidationResultStack.m b/CleverTapSDK/CTValidationResultStack.m index 17d05d71..27b2953e 100644 --- a/CleverTapSDK/CTValidationResultStack.m +++ b/CleverTapSDK/CTValidationResultStack.m @@ -41,20 +41,26 @@ - (void)pushValidationResult:(CTValidationResult *)vr { CleverTapLogInternal(self.config.logLevel, @"%@: no object in the validation result", self); return; } - [self.pendingValidationResults addObject:vr]; - if (self.pendingValidationResults && [self.pendingValidationResults count] > 50) { - [self.pendingValidationResults removeObjectAtIndex:0]; + + @synchronized (self.pendingValidationResults) { + [self.pendingValidationResults addObject:vr]; + if (self.pendingValidationResults.count > 50) { + [self.pendingValidationResults removeObjectAtIndex:0]; + } } } - (CTValidationResult *)popValidationResult { CTValidationResult *vr = nil; - if (self.pendingValidationResults && [self.pendingValidationResults count] > 0) { - vr = self.pendingValidationResults[0]; - [self.pendingValidationResults removeObjectAtIndex:0]; + + @synchronized (self.pendingValidationResults) { + if (self.pendingValidationResults.count > 0) { + vr = self.pendingValidationResults[0]; + [self.pendingValidationResults removeObjectAtIndex:0]; + } } + return vr; } - @end