Skip to content

Commit 37553e1

Browse files
author
kai
committed
add @synchronized (self) to function scope
1 parent a6c9f93 commit 37553e1

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

IdentityCore/src/requests/broker/MSIDGCDStarvationDetector.m

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ - (void)startMonitoring
5353

5454
self.shouldStop = NO;
5555
self.monitoringStartTime = [NSDate date];
56-
_monitorThread = [[NSThread alloc] initWithTarget:self
56+
self.monitorThread = [[NSThread alloc] initWithTarget:self
5757
selector:@selector(monitorLoop)
5858
object:nil];
59-
_monitorThread.name = [NSString stringWithFormat:@"%@-%@", @"com.microsoft.msid.MSIDGCDStarvationDetector.thread", [NSUUID UUID].UUIDString];
60-
[_monitorThread start];
59+
self.monitorThread.name = [NSString stringWithFormat:@"%@-%@", @"com.microsoft.msid.MSIDGCDStarvationDetector.thread", [NSUUID UUID].UUIDString];
60+
[self.monitorThread start];
6161
self.running = YES;
6262
}
6363
}
@@ -75,35 +75,34 @@ - (NSTimeInterval)stopMonitoring {
7575
}
7676

7777
- (void)monitorLoop {
78-
@autoreleasepool {
79-
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"GCDStarvationDetector -- started on thread: %@", [NSThread currentThread]);
80-
81-
while (YES) {
82-
if (self.shouldStop || [NSThread currentThread].isCancelled) {
83-
break;
84-
}
85-
86-
NSTimeInterval elapsed = [[NSDate date] timeIntervalSinceDate:self.monitoringStartTime];
87-
if (elapsed >= maxMonitoringDuration) {
88-
MSID_LOG_WITH_CTX(MSIDLogLevelWarning, nil, @"GCDStarvationDetector -- reached maximum duration (%.2fs), stopping", elapsed);
89-
[self stopMonitoring];
90-
break;
91-
}
92-
93-
@synchronized (self) {
78+
@synchronized (self) {
79+
@autoreleasepool {
80+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"GCDStarvationDetector -- started on thread: %@", [NSThread currentThread]);
81+
82+
while (YES) {
83+
if (self.shouldStop || [NSThread currentThread].isCancelled) {
84+
break;
85+
}
86+
87+
NSTimeInterval elapsed = [[NSDate date] timeIntervalSinceDate:self.monitoringStartTime];
88+
if (elapsed >= maxMonitoringDuration) {
89+
MSID_LOG_WITH_CTX(MSIDLogLevelWarning, nil, @"GCDStarvationDetector -- reached maximum duration (%.2fs), stopping", elapsed);
90+
[self stopMonitoring];
91+
break;
92+
}
93+
9494
BOOL starved = [self isThreadStarvedWithTimeout:starvationCheckTimeout];
9595
self.totalPingCount += 1;
9696
if (starved) {
9797
self.gcdStarvedDuration += (starvationCheckTimeout + starvationCheckInterval);
9898
self.starvedPingCount += 1;
9999
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose, nil, @"GCDStarvationDetector -- starvation detected, cumulative duration: %.2fms", self.gcdStarvedDuration * 1000);
100100
}
101+
102+
[NSThread sleepForTimeInterval:starvationCheckInterval];
103+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"GCDStarvationDetector -- stopped on thread: %@", [NSThread currentThread]);
101104
}
102-
103-
[NSThread sleepForTimeInterval:starvationCheckInterval];
104105
}
105-
106-
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"GCDStarvationDetector -- stopped on thread: %@", [NSThread currentThread]);
107106
}
108107
}
109108

0 commit comments

Comments
 (0)