fix: make Ctrl+C cancel ObjC semaphore waits within ~1s
semaphore_wait_with_timeout now polls photos_cancelled every second instead of blocking for the full timeout duration
This commit is contained in:
@@ -10,8 +10,15 @@ static NSDictionary *make_error_dict(NSString *message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static BOOL semaphore_wait_with_timeout(dispatch_semaphore_t sem, int64_t seconds) {
|
static BOOL semaphore_wait_with_timeout(dispatch_semaphore_t sem, int64_t seconds) {
|
||||||
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC);
|
int64_t deadline = (int64_t)[NSDate timeIntervalSinceReferenceDate] + seconds;
|
||||||
return dispatch_semaphore_wait(sem, timeout) == 0;
|
while (1) {
|
||||||
|
if (photos_cancelled) return NO;
|
||||||
|
int64_t remaining = deadline - (int64_t)[NSDate timeIntervalSinceReferenceDate];
|
||||||
|
if (remaining <= 0) return NO;
|
||||||
|
int64_t waitSecs = remaining < 1 ? remaining : 1;
|
||||||
|
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, waitSecs * NSEC_PER_SEC);
|
||||||
|
if (dispatch_semaphore_wait(sem, timeout) == 0) return YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSDictionary *collection_to_dict(PHCollection *collection) {
|
static NSDictionary *collection_to_dict(PHCollection *collection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user