Skip to content

Commit d3b1203

Browse files
Copilotkovidgoyal
andauthored
replace C11 atomics with dispatch_group_t to fix undeclared identifier errors
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/2f0107b0-a6e4-447c-8178-60d65038df4b Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
1 parent 983185c commit d3b1203

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

glfw/cocoa_window.m

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,41 +1759,39 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
17591759
}
17601760
char *mt = _glfw_strdup(mime);
17611761
NSMutableArray *collected_urls = [[NSMutableArray alloc] init];
1762-
_Atomic(NSInteger) *pending = (_Atomic(NSInteger) *)malloc(sizeof(_Atomic(NSInteger)));
1763-
atomic_init(pending, (NSInteger)[file_receivers count]);
1762+
dispatch_group_t group = dispatch_group_create();
17641763
NSOperationQueue *opQueue = [[NSOperationQueue alloc] init];
17651764
opQueue.maxConcurrentOperationCount = 1; // serial: safe to append to collected_urls
17661765
for (NSFilePromiseReceiver *receiver in file_receivers) {
1766+
dispatch_group_enter(group);
17671767
[receiver receivePromisedFilesAtDestination:tmpDirURL options:@{}
17681768
operationQueue:opQueue
17691769
reader:^(NSURL *fileURL, NSError *errorOrNil) {
17701770
if (!errorOrNil && fileURL) [collected_urls addObject:fileURL];
1771-
if (atomic_fetch_sub_explicit(pending, 1, memory_order_acq_rel) == 1) {
1772-
// All file promises resolved; build uri-list on the main thread
1773-
dispatch_async(dispatch_get_main_queue(), ^{
1774-
free(pending);
1775-
_GLFWwindow *w = _glfwWindowForId(wid);
1776-
if (w && w->ns.drop_data.file_promise_mapping) {
1777-
if (w->ns.drop_data.data_mapping == nil)
1778-
w->ns.drop_data.data_mapping = [[NSMutableDictionary alloc] init];
1779-
NSMutableString *uri_list = [NSMutableString stringWithCapacity:4096];
1780-
for (NSURL *url in collected_urls) {
1781-
if ([uri_list length] > 0) [uri_list appendString:@"\n"];
1782-
[uri_list appendString:url.absoluteString];
1783-
}
1784-
NSData *result = [uri_list dataUsingEncoding:NSUTF8StringEncoding];
1785-
w->ns.drop_data.data_mapping[@(mt)] = @[result, @0];
1786-
[w->ns.drop_data.file_promise_mapping removeObjectForKey:@(mt)];
1787-
const char *mimes[1] = {mt};
1788-
_glfwInputDropEvent(w, GLFW_DROP_DATA_AVAILABLE, 0, 0, mimes, 1, false);
1789-
}
1790-
[collected_urls release];
1791-
[opQueue release];
1792-
free(mt);
1793-
});
1794-
}
1771+
dispatch_group_leave(group);
17951772
}];
17961773
}
1774+
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
1775+
dispatch_release(group);
1776+
_GLFWwindow *w = _glfwWindowForId(wid);
1777+
if (w && w->ns.drop_data.file_promise_mapping) {
1778+
if (w->ns.drop_data.data_mapping == nil)
1779+
w->ns.drop_data.data_mapping = [[NSMutableDictionary alloc] init];
1780+
NSMutableString *uri_list = [NSMutableString stringWithCapacity:4096];
1781+
for (NSURL *url in collected_urls) {
1782+
if ([uri_list length] > 0) [uri_list appendString:@"\n"];
1783+
[uri_list appendString:url.absoluteString];
1784+
}
1785+
NSData *result = [uri_list dataUsingEncoding:NSUTF8StringEncoding];
1786+
w->ns.drop_data.data_mapping[@(mt)] = @[result, @0];
1787+
[w->ns.drop_data.file_promise_mapping removeObjectForKey:@(mt)];
1788+
const char *mimes[1] = {mt};
1789+
_glfwInputDropEvent(w, GLFW_DROP_DATA_AVAILABLE, 0, 0, mimes, 1, false);
1790+
}
1791+
[collected_urls release];
1792+
[opQueue release];
1793+
free(mt);
1794+
});
17971795
return 0;
17981796
}
17991797
} else if (strcmp(mime, "text/plain") == 0 || strcmp(mime, "text/plain;charset=utf-8") == 0) {

0 commit comments

Comments
 (0)