Skip to content

Commit 7351ebd

Browse files
author
garenwang
committed
修复信号量
1 parent f2b9701 commit 7351ebd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
Binary file not shown.

QCloudCore/Classes/Base/QCloudClientBase/Request/QCloudBizHTTPRequest.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ QCloudResponseSerializerBlock QCloudResponseObjectSerilizerBlock(Class modelClas
6262
};
6363

6464
@interface QCloudBizHTTPRequest ()
65+
@property (nonatomic,assign)NSInteger semp_flag;
6566
@property (nonatomic,strong,nullable)dispatch_semaphore_t semaphore;
6667
@end
6768

@@ -114,6 +115,7 @@ - (QCloudSignatureFields *)signatureFields {
114115
- (BOOL)prepareInvokeURLRequest:(NSMutableURLRequest *)urlRequest error:(NSError *__autoreleasing *)error {
115116
// NSAssert(self.runOnService, @"RUN ON SERVICE is nil%@", self.runOnService);
116117
self.semaphore = dispatch_semaphore_create(0);
118+
self.semp_flag = 1;
117119
__block NSError *localError;
118120
__block BOOL isSigned;
119121
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
@@ -147,11 +149,14 @@ - (BOOL)prepareInvokeURLRequest:(NSMutableURLRequest *)urlRequest error:(NSError
147149
}
148150
}
149151
dispatch_semaphore_signal(self.semaphore);
150-
self.semaphore = nil;
152+
self.semp_flag = 2;
151153
}];
152154
});
153155

154-
dispatch_semaphore_wait(self.semaphore, dispatch_time(DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC));
156+
if (self.semp_flag == 1) {
157+
dispatch_semaphore_wait(self.semaphore, dispatch_time(DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC));
158+
}
159+
155160
if (localError) {
156161
if (NULL != error) {
157162
*error = localError;
@@ -185,9 +190,8 @@ - (void)loadQCloudSignature {
185190
}
186191

187192
- (void)dealloc{
188-
if (self.semaphore) {
193+
if (self.semp_flag == 1) {
189194
dispatch_semaphore_signal(self.semaphore);
190-
self.semaphore = nil;
191195
}
192196
}
193197

0 commit comments

Comments
 (0)